Base64 Algorithm Explained
An interactive, bit-by-bit walkthrough of exactly how the Base64 encoding algorithm works under the hood.
Base64 isn't magic—it's just a way of reorganizing bits. Computers usually group bits into blocks of 8 (called bytes). Base64 takes those 8-bit blocks and reorganizes them into 6-bit blocks.
Because 6 bits can represent exactly 64 different values (26 = 64), we can easily map those values to 64 safe, printable characters. Type any 1 to 3 characters in the box below to see the algorithm happening in real-time.
ASCII Translation
8-Bit Binary Conversion
6-Bit Regrouping & Padding
Final Base64 Result
Understanding the Breakdown
The visualizer above demonstrates the strict 4-step process that occurs every time you Base64 encode a string:
- ASCII Translation: First, the algorithm reads the human text and translates it into its corresponding numerical ASCII value. (e.g., 'C' is 67).
- Binary Conversion: Those decimal numbers are then converted into binary (1s and 0s). Because computers operate in bytes, each character perfectly aligns into an 8-bit sequence.
- 6-Bit Regrouping: This is the crucial step. The algorithm ignores the 8-bit boundaries and smashes all the bits together into a continuous stream. It then slices that stream into new chunks of exactly 6 bits. If the stream doesn't divide evenly by 6, it pads the end with zeroes.
- Alphabet Mapping: Finally, those new 6-bit chunks are converted back into decimal numbers (which will always range from 0 to 63). The algorithm looks up that number in the standard Base64 Alphabet table to find the final character. If padding zeros were artificially added, an equals sign (
=) is appended to signal to decoders that those bits weren't part of the original data.
Why 3 Characters?
Notice how typing exactly 3 characters results in 0 equals signs? Three 8-bit bytes equals 24 bits. 24 bits perfectly divides into four 6-bit chunks (4 × 6 = 24). This is the "perfect alignment" in Base64 encoding. Any data that is a multiple of 3 bytes will never have padding!