How Base64 encoding works
Why binary data gets converted into plain text characters, and what those trailing equals signs mean.
Some systems were built to safely carry plain text but not raw binary data — older email protocols, URLs, and JSON among them. Base64 exists to package binary data as ordinary printable characters so it can pass through those channels without getting corrupted along the way.
The mechanism
Base64 works in groups of 3 bytes (24 bits) at a time, and re-slices those 24 bits into four 6-bit chunks instead. Six bits gives exactly 64 possible values, and each one maps to a character from a fixed set of 64 — the letters A–Z and a–z, the digits 0–9, plus + and /. That’s where the name comes from, and why encoded text runs roughly a third longer than the original.
Working through an example
Encoding the two letters “Hi”:
H = 01001000
i = 01101001
Combined 16 bits, split into 6-bit chunks:
010010 000110 1001(00 padded)
010010 → S
000110 → G
100100 → k
Result: SGk=
Why the equals signs show up
Base64 needs its input in clean groups of 3 bytes. When the input doesn’t divide evenly — as with these 2 bytes — the last group gets padded with zero bits, and the output gets one or two trailing = characters marking exactly how much padding was added. That’s why “Hi” encodes to SGk= with a single =, while a 1-byte input ends in ==.
What it isn’t
Base64 is encoding, not encryption. It’s trivially reversible by anyone — a way to make binary data safely transportable as text, not a way to hide or secure it.
Try it yourself in the Base64 encoder/decoder.