Encoding

Base64 Encoding Explained: Why It Exists and How to Use It

Base64 turns binary data into safe ASCII text. Learn why this was necessary, how the algorithm works, and the common variants you'll encounter.

Published August 5, 2026

Try it yourself

Base64 — free, instant, client-side

Open Base64

The Problem Base64 Solves

Computers store everything as binary data. But many systems — email protocols, HTTP headers, XML documents, URLs — were designed to carry only printable ASCII text. When you need to transmit binary data (images, files, cryptographic keys) through a text-only channel, you need to encode it as text first.

Base64 is the dominant solution. It converts binary data into a string of 64 printable ASCII characters: A–Z, a–z, 0–9, +, and /. (The name "Base64" comes from using a 64-character alphabet.)

How It Works

Base64 works by taking three bytes of input (24 bits) at a time and splitting them into four groups of 6 bits each. Each 6-bit group indexes into the 64-character alphabet to produce one output character. This is why Base64 output is always four characters for every three input bytes — a 33% size increase.

If the input is not a multiple of 3 bytes, padding characters (=) are added to make the output length a multiple of 4.

Example: the ASCII string "Man" (3 bytes) encodes to "TWFu" (4 characters).

Common Variants

Standard Base64 — uses + and / as the 62nd and 63rd characters. Standard in most contexts.

URL-safe Base64 — replaces + with - and / with _. Used in JWTs, URL parameters, and filenames, where + and / would need to be percent-encoded.

Base64 without padding — omits the = padding. Used in some JWT libraries and URLs.

MIME Base64 — identical to standard Base64 but with line breaks inserted every 76 characters. Used in email attachments.

Data URLs

Data URLs are the most common developer encounter with Base64. They embed file content directly in a URL:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...

The browser decodes the Base64 and treats it as if it were an external resource. This is useful for:

  • Embedding small images in CSS or HTML without a separate HTTP request
  • Embedding fonts in a CSS file
  • Storing small icons in JavaScript variables

The trade-off: Base64 is ~33% larger than the original binary, and the browser cannot cache the embedded resource separately.

Common Mistakes

Using Base64 for encryption. Base64 is encoding, not encryption. Anyone can decode Base64 without a key. Never use Base64 as a security measure.

Encoding large files. Base64 is appropriate for small resources. For large files, use a proper binary transfer mechanism.

Forgetting the variant. If a Base64 string with + or / ends up in a URL parameter, the + is interpreted as a space and / causes path issues. Use URL-safe Base64 or percent-encode the standard output.

Try It

The Base64 tool on Syntaxly encodes and decodes Base64 in the browser. Paste text or a data URL, switch between Standard and URL-safe variants, and get the result instantly.

Try it yourself

Base64 — free, instant, client-side

Open Base64

More Encoding guides

Encoding

JSON Web Tokens: Structure, Claims, and Security

JWTs are everywhere in modern auth. Learn what the three parts are, what the standard claims mean, and the security mistakes that expose your application.

Encoding

URL Encoding: Percent-Encoding and Safe Characters

Not all characters are safe in URLs. Learn which characters need encoding, how percent-encoding works, and when to use encodeURI vs. encodeURIComponent.

© 2026. Syntaxly | Built for the minimalist developer.