Skip to content
Developer Guides

What Is Base64 Encoding? Simple Explanation with Worked Bitwise Examples

Ever wonder why images are embedded as long strings starting with data:image/png;base64? Learn how Base64 transforms binary bytes into ASCII text, how padding works, and its 33% overhead.

EZ
EveryZap Editorial TeamTechnical Guides & Reference
Published March 9, 2026
6 min read
Table of Contents7 sections

Why Base64 Exists: The ASCII Transmission Problem

In the early days of computing, internet protocols (such as SMTP for email and early HTTP) were engineered exclusively to transmit 7-bit ASCII English text characters.

When engineers attempted to send raw binary files (such as JPEG images, audio files, or compiled binaries) over these legacy channels, mail servers and routers would corrupt the data by modifying control characters, line endings, or null bytes (0x00).

Base64 was invented under RFC 4648 to solve this dilemma: it safely encodes arbitrary binary data using only 64 universal printable ASCII characters that can pass through any network protocol or firewall without corruption.

How Base64 Works: The 24-Bit to 6-Bit Split

Base64 groups binary data into chunks of 3 bytes (24 bits total). It then divides those 24 bits into 4 groups of 6 bits each.

Because 2^6 = 64, each 6-bit group corresponds directly to an index between 0 and 63 in the Base64 alphabet:

  • Indices 0–25 map to uppercase letters: A–Z
  • Indices 26–51 map to lowercase letters: a–z
  • Indices 52–61 map to decimal digits: 0–9
  • Index 62 maps to plus symbol (+)
  • Index 63 maps to forward slash (/)

Worked Example: Encoding the Word "Zap"

Let us manually trace how the 3-letter word "Zap" converts into Base64 step by step:

1

Convert ASCII Characters to 8-Bit Binary

'Z' (ASCII 90) = 01011010. 'a' (ASCII 97) = 01100001. 'p' (ASCII 112) = 01110000. Combined 24-bit stream: 010110100110000101110000.

2

Partition into Four 6-Bit Chunks

Chunk 1: 010110 (decimal 22). Chunk 2: 100110 (decimal 38). Chunk 3: 000101 (decimal 5). Chunk 4: 110000 (decimal 48).

3

Map Decimals to the Base64 Alphabet

Decimal 22 = 'W'. Decimal 38 = 'm'. Decimal 5 = 'F'. Decimal 48 = 'w'.

4

Final Encoded Output

The word "Zap" encodes cleanly to "WmFw"!

The 33% Size Overhead Penalty

Notice that in the example above, 3 input bytes expanded into 4 output characters. Because 4 / 3 = 1.333..., Base64 encoding ALWAYS increases data payload size by approximately 33%.

This is why you should avoid embedding huge multi-megabyte images as inline Base64 data URLs in CSS or HTML, as it inflates file size and impairs browser caching.

Why Do Base64 Strings End with "="?

What happens if your input byte count is not an exact multiple of 3? (For example, 1 byte or 2 bytes).

• If 1 byte is provided (8 bits): The encoder pads 4 zero bits to form two 6-bit blocks, and appends two equals signs ("==") to complete the 4-character quartet.

• If 2 bytes are provided (16 bits): The encoder pads 2 zero bits to form three 6-bit blocks, and appends one equals sign ("=") to finish the quartet.

Common Real-World Use Cases

Developers encounter Base64 continuously in modern web engineering:

  • Data URLs: Embedding small SVG or PNG icons directly in HTML (`data:image/png;base64,...`) to avoid extra HTTP requests.
  • HTTP Basic Authentication: Credentials are transmitted in HTTP headers as `Authorization: Basic <base64(username:password)>.`
  • JSON Web Tokens (JWT): The header and payload of a JWT are Base64URL-encoded JSON objects separated by dots.
  • Email Attachments: MIME protocols encode email file attachments in Base64 for bulletproof transit.
Free Companion Tool

Try the EveryZap Base64 Encoder & Decoder

Encode and decode Base64 and Base64URL strings online with UTF-8 Unicode support, emoji handling, auto-validation, and client-side processing. Calculate instantly directly in your browser.

No Signup Required In-Browser
Open Base64 Encoder & Decoder

Sources & Reference Standards

Formulas, conversion rules, and technical specifications referenced in this guide are derived from published academic and web standards:

EZ

EveryZap Editorial Standards

This guide was researched and published by the EveryZap Editorial Team. EveryZap builds free, privacy-first web utilities and publishes documented calculation formulas and specifications. Have feedback, correction, or university formula update? Contact our editors.

Frequently Asked Questions

Common questions regarding What Is Base64 Encoding? Simple Explanation with Worked Bitwise Examples.

What is the difference between Base64 and Base64URL?

Standard Base64 contains '+' and '/', which have special reserved meanings in URL query parameters. Base64URL replaces '+' with '-' (dash), replaces '/' with '_' (underscore), and omits '=' padding.

Is Base64 considered encryption?

No! Base64 is strictly a representation format with zero keys and zero security. Anyone in the world can reverse Base64 in less than a millisecond.

How do I encode or decode Base64 in JavaScript?

Modern web browsers provide built-in functions: `btoa(string)` encodes ASCII to Base64, and `atob(base64)` decodes Base64 back to text.

Table of Contents7 sections
Recommended Guides

Continue Reading

View all guides →