FTJ
← Blog
Developer

Base64 Encoding: What It Does and Why It's Everywhere

Base64 shows up in data URIs, email attachments, and auth tokens. Here's what it actually does and when you'd use it.

# Base64 Encoding: What It Does and Why It's Everywhere

Base64 shows up in data URIs, email attachments, JWT tokens, and API responses. It's not encryption — it's encoding. The difference matters.

What Base64 Does

Base64 converts binary data into ASCII text. Any byte — 0 to 255 — becomes one of 64 printable characters (A-Z, a-z, 0-9, +, /). This makes binary data safe to transmit through text-only channels like email, JSON, or HTTP headers.

Every 3 bytes of binary become 4 characters of Base64. That's why Base64 output is about 33% larger than the input.

Why It Exists

In the early internet, many protocols only handled ASCII text. Email (SMTP) couldn't transmit binary data directly. Base64 was invented to encode binary attachments as text, transmit them, then decode back to binary on the other end.

The same problem exists today with JSON. JSON can't contain raw binary data — you'd have to escape it somehow. Base64 is the standard solution.

Common Use Cases

  1. Data URIs — Embed small images directly in HTML/CSS: <img src="data:image/png;base64,iVBOR...">
  2. JWT tokens — The header and payload of a JWT are Base64-encoded JSON
  3. Email attachments — MIME encodes attachments as Base64
  4. API responses — Binary data (like images) in JSON APIs
  5. Source maps — Compressed source map data

When NOT to Use Base64

  • Large files — A 1MB image becomes 1.33MB as Base64. Use a URL instead.
  • Encryption — Base64 is encoding, not encryption. Anyone can decode it.
  • Data compression — Base64 makes data bigger, not smaller. Use gzip.

Base64 vs Hex

Base64Hex
Charset64 chars16 chars
Size overhead+33%+100%
ReadabilityLowerHigher
Use caseTransmissionDebugging

Encoding and Decoding

In JavaScript: btoa('Hello')SGVsbG8=, atob('SGVsbG8=')Hello

Or use our Base64 Encoder/Decoder for a cleaner interface with Unicode support. Free, no signup.

Try These Tools

More Articles