Base64 Algorithm Explained
An interactive, bit-by-bit walkthrough of exactly how the Base64 encoding algorithm works under the hood.
Published on July 6, 2026•10 min read
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.
STEP 1
ASCII Translation
C
67
a
97
t
116
STEP 2
8-Bit Binary Conversion
Byte 1
01000011
Byte 2
01100001
Byte 3
01110100
That's 24 total bits of input.
STEP 3
6-Bit Regrouping & Padding
Chunk 1
010000
Decimal: 16
Chunk 2
110110
Decimal: 54
Chunk 3
000101
Decimal: 5
Chunk 4
110100
Decimal: 52
STEP 4
Final Base64 Result
Q
2
F
0
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!