How Base64 Decoding Works: Behind the 6-Bit Math
Step-by-step mathematical breakdown of how Base64 decoders convert four 6-bit characters back into three original 8-bit bytes.
Try Toolstack's Base64 Decoder
Free, instantaneous, and processes 100% locally in your browser.
Decoding Base64 is the exact inverse of the encoding transformation. While encoding splits three 8-bit bytes (24 bits total) into four 6-bit indices, decoding takes groups of four characters, maps them back to their numeric values (0–63), and packs them into three standard 8-bit bytes.
Step-by-Step Bitwise Reassembly
1. Lookup: Each character in the quartet is matched against the 64-character table to obtain its 6-bit integer value (v1, v2, v3, v4).
2. Bit Shifting: The four 6-bit numbers are concatenated into a single 24-bit integer using bitwise operations: (v1 << 18) | (v2 << 12) | (v3 << 6) | v4.
3. Extraction: The three original bytes are extracted using bitmasks: Byte 1 is (bits >> 16) & 0xFF, Byte 2 is (bits >> 8) & 0xFF, and Byte 3 is bits & 0xFF.
Handling Padding Characters
When the input string ends with "=" or "==", the decoder recognizes that the original data stream ended on a 1-byte or 2-byte boundary. A single "=" indicates that the last quartet contains only two real bytes; "==" indicates that only one real byte was encoded.
Modern web browsers implement this natively in JavaScript using the `atob()` function or the more robust `TextDecoder` API for international UTF-8 strings.
More Guides in Base64 & Encoding
Explore More Free Tools on Toolstack
Client-side developer utilities, image converters, calculators, and educational engineering guides.
Word Counter
Count words, characters with/without spaces, sentences, and paragraphs in real time with reading speed metrics.
PDF Compressor
Reduce PDF document file size directly in your browser with zero server uploads.
Image Compressor & Resizer
Batch compress and scale JPG, PNG, and WebP images with custom quality settings.
URL Encoder & Decoder
Encode and decode query strings, special characters, and parameters with RFC 3986 percent-encoding.
JSON Validator & Formatter
Beautify, validate, minify, and auto-fix JSON syntax errors with real-time line/column diagnostics.
HEIC to JPG Converter
Convert Apple iPhone HEIC and HEIF photos to high-quality JPG directly in your browser.