What Is Base64 and How Does It Work?
Every time an image is embedded in an email or a token is pasted into a URL, Base64 is usually involved. It is one of the most common text encodings in computing, yet also one of the least understood. Here is exactly how it works.
Base64 is an encoding, not encryption
Base64 takes binary data — any sequence of bytes — and represents it with a short alphabet of 64 printable ASCII characters: A–Z, a–z, 0–9, plus + and /. That is why it is called Base64: each output character stands for 6 bits, so 3 input bytes become 4 output characters.
Why the output is about 33% longer
Encoding 3 bytes as 4 characters of 6 bits each costs one extra character per three bytes, a 4:3 ratio. A 100 KB file therefore produces roughly a 133 KB Base64 string — the overhead is the price of making arbitrary bytes safe to travel through text-based systems.
What padding is for
When the input length is not a multiple of three, the last group is shorter, so the encoder appends = characters to complete it. Every reader strips them before decoding, which is why most Base64 strings end in zero, one or two equals signs.
Where Base64 appears
Email attachments (MIME), JSON payloads and JWTs, data URLs in HTML and CSS, and configuration values that must survive text-only transport. Whenever bytes must pass through a channel that only understands printable text, Base64 is the bridge.
Common mistakes to avoid
Never use Base64 to keep data secret: it is an open encoding that anyone can reverse with a decoder. Also remember that Unicode is encoded as UTF-8 bytes first, so the exact string depends on that choice. The in-browser encoder and decoder handle both correctly.