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.
Bulk CSV Data Cleaner
Clean, deduplicate, filter, reorder columns, and sanitize CSV datasets 100% in browser.
Redirect Checker & GSC Analyzer
Audit HTTP redirect chains (301, 302, 308), loops, and Google Search Console exports.
Bulk URL Status Checker
Batch check HTTP status codes (200, 301, 404, 500), latency, and hops in bulk.
Time Zone Meeting Planner
Find overlapping working hours across 2 to 10 cities and copy meeting invites instantly.
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.