Toolvona
Developer Tools & Programming

What Is Base64 Encoding and How Does It Work? Complete Visual Guide

Ever wondered what Base64 strings really are? Learn how 8-bit binary data is transformed into 6-bit ASCII characters for safe email and web transmission.

Updated: 18 November, 2026•8 min read
What Is Base64 Encoding and How Does It Work? Complete Visual Guide

Introduction#

If you have ever inspected an inline image in HTML, decoded an authorization header in an HTTP request, or examined an email attachment over SMTP, you have encountered strings that look like this:

text
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9h...

This is Base64 encoding. Many developers mistakenly believe that Base64 is a form of encryption or compression. In reality, it is neither! Base64 actually increases file size by approximately 33%.

So why do we use it everywhere across the internet? In this visual guide, you will learn the mathematical foundation of Base64, how 8-bit binary is converted into safe 6-bit ASCII, and when to use data URIs.

Why Does Base64 Exist? (The Transmission Problem)#

Early computer networks and legacy communication protocols (like 7-bit ASCII SMTP email) were designed strictly to transmit plain English characters.

If you attempted to send a binary file (such as a JPEG image, executable, or compressed ZIP archive) through these legacy channels, control characters like NULL (0x00), line feeds (0x0A), or carriage returns (0x0D) would be misinterpreted by intermediate routers or gateways, corrupting the file.

Base64 solves this problem by encoding arbitrary raw binary bytes into a safe subset of 64 printable ASCII characters that traverse any network gateway intact.

How Base64 Works: The 6-Bit Math#

Computers store data in 8-bit bytes (256 possibilities). Base64 represents data using a 6-bit alphabet (64 possibilities).

The encoding process follows a simple mathematical rule:

  • Take 3 input bytes (24 bits total: 3 × 8).
  • Split those 24 bits into 4 chunks of 6 bits each (4 × 6 = 24).
  • Map each 6-bit numerical value (0 to 63) to its corresponding character in the Base64 index table.
  • Because 3 input bytes become 4 output characters, Base64 universally expands data payload size by 33.3% (4 ÷ 3 = 1.333).

    The 64-Character Base64 Index Table#

    Decimal ValueBinary (6-bit)ASCII Character
    0 – 25000000 – 011001A – Z (Uppercase alphabet)
    26 – 51011010 – 110011a – z (Lowercase alphabet)
    52 – 61110100 – 1111010 – 9 (Numeric digits)
    62111110+ (Plus sign)
    63111111/ (Forward slash)
    PaddingN/A= (Equals sign)

    Why Does Base64 End with '=' (Padding)?#

    What happens if your input text is not a clean multiple of 3 bytes?

  • If there is 1 remaining byte (8 bits), the encoder pads 4 zero bits to make two 6-bit characters, followed by two = signs (==).
  • If there are 2 remaining bytes (16 bits), the encoder pads 2 zero bits to make three 6-bit characters, followed by one = sign (=).
  • Base64 vs Encryption vs Compression#

    TechnologyPurposeCan Anyone Revert It?Impact on Size
    Base64 EncodingSafe network transport✅ Yes, instantly (No key required)Increases by 33%
    AES-256 EncryptionConfidentiality & secrecy❌ No (Requires secret key)Slightly increases / pads
    Gzip CompressionBandwidth reduction✅ Yes, with standard decompressionReduces by 50% – 80%

    Real-World Web Use Cases#

  • Data URIs in CSS/HTML: Inlining microscopic SVG icons or 1x1 tracking pixels directly inside CSS stylesheets to save an HTTP round-trip request.
  • HTTP Basic Authentication: Sending client credentials in the Authorization: Basic <base64> header.
  • JWT (JSON Web Tokens): Encoding the header and payload objects in URL-safe Base64.
  • Encode and decode data locally without exposing sensitive tokens:

  • Base64 Encoder – Convert plain text, JSON, and binary files into Base64 strings.
  • Base64 Decoder – Decode Base64 strings back to readable UTF-8 text or downloadable files.
  • Image to Base64 Converter – Generate instant data:image/... URI strings for web development.
  • URL Encoder / Decoder – Escape URL query parameters safely.
  • Frequently Asked Questions#

    Is Base64 safe for storing passwords?#

    Absolutely not! Base64 is an open, reversible encoding scheme, not encryption. Storing passwords in Base64 is effectively storing them in plain text. Always use salted cryptographic hashing (like Argon2id or bcrypt).

    What is URL-safe Base64?#

    Standard Base64 uses + and /, which have reserved meanings in URL query strings. URL-Safe Base64 (RFC 4648) replaces + with - (hyphen) and / with _ (underscore), and omits = padding.

    Summary#

    Base64 is an indispensable web utility that trades a 33% increase in data size for 100% transmission reliability across arbitrary networks. Remembering that it is an encoding method—not encryption—ensures you use it effectively and securely.

    Tags:Base64Binary EncodingData URIWeb ArchitectureComputer Science