The Base64 Alphabet
You'll learn: The exact 64 characters that make up Base64 encoding and how padding keeps everything aligned.
The 64-Character Set
Base64 encoding uses a specific alphabet of 64 printable ASCII characters to represent binary data. Think of it like a special language with only 64 "letters" instead of the usual 256 possible byte values.
The Base64 alphabet consists of:
- A-Z (26 uppercase letters)
- a-z (26 lowercase letters)
- 0-9 (10 digits)
- + and / (2 special characters)
That's exactly 64 characters (26 + 26 + 10 + 2 = 64). Each character represents a 6-bit value (since 2^6 = 64).
How Binary Maps to Base64
Every three bytes (24 bits) of binary data gets encoded into four Base64 characters (4 × 6 = 24 bits). It's like cutting a pizza into equal slices: 3 bytes become 4 characters, maintaining the same information in a different form.
The Padding Character: =
When your data doesn't divide evenly by 3 bytes, Base64 adds padding using the = character to complete the final group of four characters.
- If 1 byte remains: add
==(two padding characters) - If 2 bytes remain: add
=(one padding character) - If 3 bytes fit perfectly: no padding needed
For example, encoding 2 bytes produces 3 meaningful Base64 characters plus one = for padding.
Key Takeaway: Base64 uses 64 specific characters (A-Z, a-z, 0-9, +, /) to encode binary data in a 3-to-4 byte ratio, with = characters padding the output to complete the final group when needed.