What Is Base64 Encoding? The Complete Guide to RFC 4648
Learn what Base64 encoding is, how the 6-bit chunking algorithm works, padding (=) calculation, and practical applications in HTTP headers and Data URIs.
What Is Base64?
Base64 is a binary-to-text encoding scheme defined in RFC 4648. It converts arbitrary binary data or text into an ASCII string format using a 64-character alphabet:
Alphabet: A-Z (26), a-z (26), 0-9 (10), + (1), / (1) = 64 characters
How the 6-Bit Algorithm Works
- The encoder takes 3 bytes of input data (3 × 8 = 24 bits).
- It divides the 24 bits into 4 groups of 6 bits each (4 × 6 = 24 bits).
- Each 6-bit group represents a number from 0 to 63, which maps directly to an ASCII character in the Base64 index table.
Padding (=) Explained
If the input byte count is not evenly divisible by 3, padding characters (=) are appended:
- If 1 byte remains (8 bits): Produces 2 Base64 characters and
==padding. - If 2 bytes remain (16 bits): Produces 3 Base64 characters and
=padding.