How Base64 Works: 6-Bit Binary to 8-Bit ASCII Transformation
Base64 is a binary-to-text encoding scheme defined in RFC 4648 designed to transport arbitrary binary data across text-only protocols like HTTP, SMTP (email), and JSON. The algorithm splits binary data into 6-bit chunks (since 2^6 = 64). Each 6-bit integer maps to an index in the 64-character ASCII table (A-Z, a-z, 0-9, +, /). Because every 3 input bytes (24 bits) are represented by 4 output characters, Base64 increases data size by exactly 33.3% (plus up to two "=" padding characters).
// Binary to Base64 mapping concept
// Input Bytes: 'M' (01001101), 'a' (01100001), 'n' (01101110)
// 24-bit stream: 010011010110000101101110
// 6-bit groups: 010011 (19), 010110 (22), 000101 (5), 101110 (46)
// Base64 chars: 'T', 'W', 'F', 'u' => "TWFu"