Base64 Encoding: How It Works
Decode the mystery of Base64 — the encoding scheme used in emails, JWTs, and data transmission.
Why Binary Needs Text Representation
Many systems, including email, HTTP headers, and XML, were designed to handle text but not arbitrary binary data. A byte value of 0x00 (null) or 0x1A (control character) can cause parsing failures or data corruption.
Base64 encoding converts arbitrary binary data into a subset of ASCII characters that is safe for text-only systems, allowing binary content like images and certificates to be embedded in text-based protocols.
6-Bit Grouping from 8-Bit Bytes
Base64 works by taking three 8-bit bytes (24 bits total) and splitting them into four 6-bit groups. Each 6-bit group represents a value from 0 to 63, which maps to one character in the Base64 alphabet.
This 3-to-4 ratio means every 3 bytes of input produce 4 characters of output, a 33% size increase. The math works out evenly because 3 bytes = 24 bits = 4 groups of 6 bits.
All lessons in this course
- Base64 Encoding: How It Works
- ASCII, Unicode, and Text Representation
- Hexadecimal in Cryptographic Output
- Encoding vs Encryption vs Hashing