Irreva logo
Explore Irreva
DeveloperMay 2, 2026· 7 min read· Updated June 10, 2026

Base64 Encoding Explained — What It Is, How It Works, and When to Use It

Hasanur Rahman

Written by Hasanur Rahman

Founder & Full-Stack Developer · Irreva · Rangpur, Bangladesh

Base64 shows up constantly in web development — in data URIs, in JWT tokens, in email attachments, in API responses. But most developers use it without a clear mental model of what it actually does. This guide explains Base64 encoding from first principles, in plain English.

The problem Base64 solves

Computers store everything as binary — sequences of 0s and 1s. When you need to transmit binary data through a channel designed only for text (like email, HTTP headers, or a JSON field), you have a problem: binary bytes include control characters and byte values that text protocols may interpret as commands, truncate, or corrupt.

Base64 solves this by representing arbitrary binary data using only 64 characters that are safe in any text context: A–Z, a–z, 0–9, plus (+), and slash (/), with equals (=) used for padding. Any binary data can be encoded into this safe character set and decoded back to the original bytes exactly.

How the encoding actually works

Base64 takes your input bytes in groups of three. Three bytes = 24 bits. It splits those 24 bits into four groups of 6 bits each. Each 6-bit group represents a number from 0 to 63, which maps to one character in the Base64 alphabet.

So every 3 input bytes become 4 output characters. This is why Base64 makes data roughly 33% larger — the encoding is 4/3 the size of the input. The padding character (=) is added at the end when the input isn't a multiple of 3 bytes.

This also means Base64 is not encryption. It's just a different representation of the same data. Anyone can decode Base64 — there's no key or secret involved.

Where Base64 appears in practice

Data URIs embed binary files directly in HTML or CSS without a separate file request: `<img src="data:image/png;base64,iVBOR...">`. This is useful for small icons in email templates and critical above-the-fold images where you want to avoid a network round-trip.

JWT tokens use Base64URL encoding (a slight variant that replaces + with - and / with _ for URL safety) to encode the header and payload sections. If you split a JWT at the dots and decode the first two parts from Base64, you can read the token's contents.

Email attachments — despite the modern web — still use MIME encoding with Base64 to attach binary files to plain-text email messages. The file is encoded to Base64 and embedded in the email body.

Basic Authentication HTTP headers encode `username:password` as Base64 in the Authorization header. This does not provide security on its own — the credentials can be trivially decoded. HTTPS is what provides the actual security.

Base64URL vs standard Base64

Standard Base64 uses + and / characters, which have special meanings in URLs. Base64URL replaces + with - and / with _, making the encoded output safe to include in URLs and filenames without percent-encoding.

If you're encoding something for a JWT token, a filename, or a URL parameter, use Base64URL. For embedding in HTML, email, or JSON, standard Base64 is fine.

Common misconceptions about Base64

Base64 is not compression. It makes data larger, not smaller. If you need to reduce size, compress first (with gzip or brotli) and then Base64-encode if necessary.

Base64 is not encryption. The encoded content is trivially reversible by anyone who knows it's Base64-encoded. Don't use it to obscure passwords or sensitive data.

Base64-encoded strings often end with one or two = padding characters. If your decoder rejects them or your encoder omits them, that's usually fine — the = characters are optional and many implementations accept Base64 without them.

Frequently Asked Questions

How do I identify a Base64-encoded string?

Look for a long string of letters, numbers, plus signs, and forward slashes, often ending with one or two equals signs. If it ends in = or ==, it's almost certainly Base64. Paste it into the decoder to confirm.

Why does Base64 make files 33% larger?

Because 3 bytes of binary data become 4 Base64 characters. Each character requires 8 bits of storage, so 3 bytes (24 bits) of input becomes 4 bytes (32 bits) of Base64 output — a 4/3 ratio, or 33% overhead.

Can I use Base64 for passwords?

Not for security. Base64 is reversible without any key. Anyone who sees a Base64-encoded password can decode it instantly. For passwords, use proper hashing algorithms like bcrypt, scrypt, or Argon2.

What does the btoa() function do in JavaScript?

btoa() encodes a string to Base64. The name stands for Binary To ASCII. Its counterpart atob() (ASCII To Binary) decodes Base64 back to a string. Both are built into browsers and Node.js. The Irreva Base64 tool uses these native functions internally.

Is Base64 the same as hexadecimal encoding?

No. Both represent binary data as text, but differently. Hex uses 16 characters (0-9, a-f) and represents each byte as 2 hex characters, doubling the size. Base64 uses 64 characters and represents 3 bytes as 4 characters, adding only 33% overhead. Base64 is more efficient for larger data.

Hasanur Rahman

About the author

Hasanur Rahman

Founder & Full-Stack Developer · Irreva · Rangpur, Bangladesh

Hasanur Rahman is the founder of Irreva and a full-stack developer based in Rangpur, Bangladesh. He builds all of Irreva's tools with a focus on privacy-first, browser-based processing.