Learntrix
Notice: CHECK FACTS BEFORE PUBLISHING — Verified against IETF RFC 4648
Published by Learntrix··5 min read

How Base64 Encoding & Decoding Works in Computing

Base64 represents arbitrary binary bytes using 64 safe ASCII characters, allowing binary documents and image assets to transmit over text protocols like HTTP and SMTP without corruption.

1. 8-Bit to 6-Bit Grouping

Binary data consists of 8-bit octets (bytes). Base64 takes groups of three 8-bit bytes (24 bits in total) and breaks them into four 6-bit chunks (6 bits each = 2⁶ = 64 possible values).

Each 6-bit chunk maps to an index in the Base64 alphabet: A–Z (0–25), a–z (26–51), 0–9 (52–61), + (62), and / (63).

2. Padding with Equals Signs

When input bytes are not evenly divisible by 3, padding is required. If 1 byte remains (8 bits), it forms two 6-bit units with zero padding, followed by "==". If 2 bytes remain (16 bits), they form three 6-bit units followed by "=".