← Home Β· πŸ”€ Base64 Encoder

Base64 Encoding Explained: How It Works, Why 33% Overhead, and Examples

Updated August 22, 2026 Β· Read time: ~5 min Β· Part of the Web Toolkit dev guide series

Base64 is everywhere in web development β€” in email attachments, data: URIs, JWT tokens, and image uploads β€” yet most developers have only a fuzzy idea of what it actually does. Here's the complete plain-English explanation: what the encoding is, how the byte math works, and why it makes data 33% bigger.

The one-line summary

Base64 converts binary data into a safe 64-character text alphabet (A–Z, a–z, 0–9, +, /) so it can travel through text-only channels like JSON, HTML, email, or URLs. Every 3 bytes of input become 4 text characters; if the input isn't divisible by three, padding = characters make up the difference.

1. Why 64 characters?

A byte is 8 bits and can hold 256 values (0–255). Many of those values are control characters, quotes, newlines, or non-printable β€” hostile to text protocols. Base64 uses the largest truly safe set: 26 uppercase + 26 lowercase + 10 digits + 2 symbols = 64 printable characters, which need only 6 bits each (2⁢ = 64).

Alphabet:  ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Index 0-25 = A-Z, 26-51 = a-z, 52-61 = 0-9, 62 = '+', 63 = '/'

2. The math: 3 bytes β†’ 4 characters

The encoder takes three 8-bit bytes (24 bits in total) and splits them into four 6-bit groups. Each 6-bit group (value 0–63) indexes the alphabet above:

Input:   Man  β†’  bytes: 0x4D 0x61 0x6E
Bits:    010011 010110 000101 101110     (24 bits β†’ 4Γ—6)
Output:  T      W      F      u          = "TWFu"

Because 24 is the least common multiple of 6 and 8, the math fits perfectly on three-byte boundaries β€” which is why output is always a multiple of 4 characters.

3. Why 33% overhead, and what about padding?

8 bits in β†’ 6 bits out per character. The ratio is 8/6 = 4/3, i.e. every 3 input bytes produce 4 output characters, each storing only 6 bits of real data. That fixed 4/3 ratio is the famous 33.3% size increase (4/3 βˆ’ 1).

When input length isn't a multiple of 3, the encoder pads:

Input bytesBitsBase64 outputPadding
3 (e.g. "Man")24TWFunone
2 (e.g. "Ma")16TWE=1Γ— =
1 (e.g. "M")8TQ==2Γ— =

The = tells decoders the final group is short. Some implementations strip padding (URL-safe JWT base64url) since = has special meaning in URLs.

4. Real-world use cases

Encode text or files instantly β€” with UTF-8 support and URL-safe mode. Runs in your browser, nothing uploaded.

Open Base64 Encoder

5. Common misconceptions

  1. "Base64 is encryption or compression" β€” No. It's a reversible encoding, publicly decodable within seconds; it adds 33%, never shrinks.
  2. "It makes data safer" β€” Only safe for text channels, not security. Never base64 for secrets.
  3. "More base64 = better" β€” For big binaries (e.g. 1 MB images), base64 inflates them 33% AND adds CPU cost; prefer real binary uploads.
  4. "Padding can be dropped freely" β€” Decoders usually cope, but keep = for strict RFC 4648 tools.

6. Frequently asked questions

Is base64 case-sensitive? Yes β€” 'A' (index 0) and 'a' (index 26) decode to different bytes.

What characters does base64 use? A–Z, a–z, 0–9, +, /, and = for padding. The URL-safe variant swaps +β†’- and /β†’_.

How do I decode base64? Reverse the process: strip padding, map each character to its 6-bit index, reassemble bytes. Any decoder (like ours) does this instantly.

Can base64 represent arbitrary files? Yes β€” any byte sequence, including images, PDFs, and executable files, can be base64-encoded and transported as text.

β˜• Support this free tool β€” every tip keeps it ad-free
← Toolkit Β· Premium Β· Privacy