RUNWEBTOOLS
English
Data Formats & Encoding

Base64 Encoding Explained: What It Is and When to Use It

Updated 2026-07-06

Base64 is one of those terms that shows up constantly — in data URIs, email attachments, API tokens, and configuration files — but is rarely explained clearly. It's often mistaken for encryption, which leads to real security mistakes. This guide explains what Base64 actually does, why it makes data bigger, where it's genuinely useful, and the myths worth unlearning.

What Base64 is

Base64 is an encoding, not encryption or compression. Its job is to represent arbitrary binary data — an image, a file, any sequence of bytes — using only 64 “safe” text characters: A–Z, a–z, 0–9, plus + and / (with = used for padding). Every one of those characters survives systems that were built to handle plain text, which is the whole reason Base64 exists.

Why it's needed

Many older but still-critical systems — email being the classic example — were designed to move text, not raw binary. Sending binary through them directly can corrupt the data: certain byte values get interpreted as control characters, stripped, or mangled. Base64 sidesteps the problem by translating binary into a text form that passes through untouched, then translating it back on the other end.

Conceptually, the round trip looks like this:

binary data  →  Base64 text  →  binary data
(original)      (safe to send)    (identical copy)

Why Base64 makes data ~33% larger

There's no free lunch. Base64 works by taking three bytes (24 bits) of input and splitting them into four 6-bit groups, each of which maps to one of the 64 characters. Three bytes in, four characters out — so the encoded output is about one-third larger than the original. That overhead is the price of making binary safe to transmit as text, and it's why you shouldn't Base64-encode large files without a good reason.

Where you'll actually see it

Data URIs

You can embed a small image directly in HTML or CSS as a Base64 data URI, avoiding a separate network request:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUh..." />

This is handy for tiny icons, but because of the 33% size penalty it's a poor choice for anything large.

Email attachments

Under the hood, email attachments are Base64-encoded so binary files can travel through the text-based email system intact.

Tokens and config

Tokens and credentials are frequently Base64-encoded so they can sit safely inside headers, URLs, or text config files. A JWT (JSON Web Token), for instance, is three Base64-encoded sections joined by dots — which is exactly why a JWT decoder can read its contents instantly.

The security myth

This is the most important thing to understand: Base64 is not encryption and provides no security whatsoever. There's no key and no secret — anyone can decode Base64 back to the original data in a fraction of a second. If you see a password or API key “protected” only by Base64, treat it as if it were written in plain text, because effectively it is.

Base64 answers the question “how do I move this data safely through a text channel?” — not “how do I keep this data secret?” For secrecy you need real encryption. It's common to combine the two: encrypt first, then Base64-encode the encrypted result so it can be transmitted as text.

Base64 and URLs

Standard Base64 uses + and /, which have special meanings in URLs and can get corrupted when passed as query parameters. A variant called Base64URL swaps them for - and _ and drops the padding, making the output safe to drop straight into a URL. If you're also wrestling with characters like spaces or ampersands in a URL, that's a job for URL encoding instead — a different tool for a different problem.

Encoding and decoding it yourself

You rarely need to do Base64 by hand, but you often need to inspect or produce it — to read a data URI, check what's inside a token, or create an embedded image. Our Base64 encoder and decoder converts text either direction instantly and entirely in your browser, so even sensitive values never leave your device. Paste Base64 to see the original, or paste text to get the encoded form.

The one-line summary

Base64 turns binary into safe text and back again, at the cost of about 33% more size, and offers zero secrecy. Use it to transport data, never to protect it.

More in Data Formats & Encoding

See all Data Formats & Encoding guides →

Tools mentioned in this guide