Base64 Encoder/Decoder

Encode text to Base64 or decode Base64 strings instantly. Our free online tool supports UTF-8 encoding and URL-safe Base64 variants. All processing happens locally in your browser for privacy.

About Encoding

  • Base64 encoding increases data size by ~33%
  • UTF-8 characters are fully supported
  • Use URL-safe mode for URLs, filenames, and JWTs
  • This is encoding, NOT encryption—it's not secure

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. It was designed to allow binary data to be transmitted through systems that only support text, such as email protocols and HTML documents.

The name "Base64" comes from the 64 characters used in the encoding: uppercase A-Z (26), lowercase a-z (26), digits 0-9 (10), and two additional characters (typically + and /).

How Base64 Works

The encoding process converts every 3 bytes (24 bits) of input into 4 characters (6 bits each = 24 bits) of output:

  1. Take 3 input bytes (24 bits)
  2. Split into 4 groups of 6 bits each
  3. Convert each 6-bit group to its corresponding Base64 character
  4. If input isn't divisible by 3, add padding (=)
Example: "Man"
M = 77 = 01001101
a = 97 = 01100001
n = 110 = 01101110

Combined: 010011 010110 000101 101110
           T       W       F       u

"Man" → "TWFu"

Common Use Cases

Embedding Images in HTML/CSS

Small images can be embedded directly in HTML or CSS using Data URIs:

<img src="data:image/png;base64,iVBORw0KGgo..." />

.icon {
  background: url(data:image/svg+xml;base64,PHN2ZyB4...);
}

Email Attachments (MIME)

Email protocols like SMTP were designed for 7-bit ASCII text. Base64 encoding allows binary attachments (images, documents) to be transmitted safely through these text-only systems.

Storing Binary in JSON/XML

JSON and XML don't natively support binary data. Base64 encoding allows you to include binary data as a text string within these formats.

API Authentication

HTTP Basic Authentication encodes credentials (username:password) in Base64:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
// Decodes to: username:password

Base64 Variants

Standard Base64 (RFC 4648)

Uses A-Z, a-z, 0-9, +, /, and = for padding. This is the most common variant used for email and general purposes.

URL-Safe Base64

Replaces + with - and / with _ to avoid URL encoding issues. The padding (=) is often omitted. Used in JWTs, URL parameters, and filenames.

MIME Base64

Same as standard but adds line breaks every 76 characters. Used in email encoding to comply with SMTP line length limits.

Important Considerations

Size Increase

Base64 encoding increases data size by approximately 33%. For every 3 bytes of input, you get 4 bytes of output. Consider this overhead when encoding large files.

Not Encryption

Base64 is NOT encryption—it provides no security. Anyone can decode Base64 data. Never use it to "protect" sensitive information. Use proper encryption (AES, RSA) for security.

Character Encoding

When encoding text, be aware of character encoding (UTF-8, UTF-16, etc.). This tool uses UTF-8, which is the most common encoding for web applications. Decoding with the wrong character set can produce garbled output.

Base64 in JavaScript

// Encode (ASCII only)
btoa("Hello");  // "SGVsbG8="

// Decode
atob("SGVsbG8=");  // "Hello"

// For Unicode text
function encodeUnicode(str) {
  return btoa(encodeURIComponent(str)
    .replace(/%([0-9A-F]{2})/g, (_, p1) => 
      String.fromCharCode('0x' + p1)));
}

function decodeUnicode(str) {
  return decodeURIComponent(atob(str)
    .split('').map(c => 
      '%' + c.charCodeAt(0).toString(16).padStart(2, '0')
    ).join(''));
}

Frequently Asked Questions

What is Base64 encoding?
Base64 is an encoding scheme that converts binary data into ASCII text using 64 printable characters (A-Z, a-z, 0-9, +, and /). It's used to safely transmit data through systems that only handle text, such as email attachments, embedding images in HTML/CSS, and storing binary data in JSON or XML.
Is Base64 encryption?
No, Base64 is encoding, not encryption. Encoding transforms data into another format for compatibility or transmission, while encryption scrambles data to protect it from unauthorized access. Base64-encoded data can be easily decoded by anyone—it provides no security. Never use Base64 to 'hide' sensitive data.
Why does Base64-encoded text become larger?
Base64 encoding increases data size by approximately 33%. This is because Base64 uses 6 bits per character (64 = 2^6) while the original binary uses 8 bits per byte. Every 3 bytes of input become 4 characters of Base64 output. The padding character '=' is added when the input length isn't divisible by 3.
What's the difference between standard and URL-safe Base64?
Standard Base64 uses '+' and '/' characters which have special meanings in URLs. URL-safe Base64 replaces these with '-' and '_' respectively, making the encoded string safe to use in URLs and filenames without additional encoding. The padding character '=' may also be omitted in URL-safe variants.
Can I encode images with Base64?
Yes, images can be encoded to Base64 for embedding directly in HTML or CSS using Data URIs (like 'data:image/png;base64,...'). This eliminates additional HTTP requests but increases HTML/CSS file size. It's best for small images like icons; larger images are more efficient as separate files.
What happens if I try to decode invalid Base64?
Attempting to decode invalid Base64 will result in an error or corrupted output. Invalid Base64 might have wrong characters, incorrect padding, or improper length. Our decoder will show an error message if the input isn't valid Base64. Ensure your input only contains valid Base64 characters (A-Z, a-z, 0-9, +, /, =).

Related Tools