Base64 encoding converts 8-bit binary data into 6-bit characters using a set of 64 ASCII characters (A-Z, a-z, 0-9, +, /). Every 3 bytes of input data are converted to 4 Base64 characters, which increases the data size by approximately 33%. Here's the technical process:
- Step 1 - Group into 3-byte blocks: The input data is divided into groups of 3 bytes (24 bits).
- Step 2 - Split into 6-bit segments: Each 24-bit block is split into four 6-bit segments.
- Step 3 - Map to Base64 characters: Each 6-bit value (0-63) is mapped to one of 64 ASCII characters: A-Z (values 0-25), a-z (26-51), 0-9 (52-61), + (62), / (63).
- Step 4 - Padding: If the input length isn't divisible by 3, padding characters (=) are added to make the output length a multiple of 4.
Example: The string "cat" (ASCII: 99, 97, 116) encodes to "Y2F0". The bytes [99, 97, 116] become binary 01100011 01100001 01110100, which splits into 6-bit groups: 011000 110110 000101 110100, mapping to Y(24) 2(54) F(5) 0(52).