DevToolbox

Base64 Encoding: What It Is and When to Use It

By Editorial team · 2026-06-14

In short: Base64 encodes arbitrary binary data as 64 printable ASCII characters by mapping every 3 bytes to 4 characters, so binary can travel safely through text-only channels like JSON, data URIs, and email. It is encoding, not encryption — it adds no security and grows the data by about 33%. Use the URL-safe variant when the value goes into a URL or token.

Base64 is one of the most quietly ubiquitous tools in software. It is how a binary image ends up inside a CSS file, how email attachments survive ancient mail servers, and how a JWT carries its claims in a URL. Yet it is also one of the most misunderstood — many developers reach for it expecting security it does not provide. This article explains what Base64 really does, with examples you can reproduce in our Base64 encode/decode tool.

What problem does Base64 solve?

Computers store everything as bytes, and a byte can hold any of 256 values. But many channels were designed to carry only text — specifically a limited set of printable characters. Email headers, URLs, XML/JSON fields, and source code all choke on raw binary or control characters.

Base64 solves this by re-encoding arbitrary bytes using just 64 safe, printable ASCII characters: A–Z, a–z, 0–9, and (in the standard alphabet) + and /. The result is text that can pass through any of those channels untouched.

How does Base64 actually work?

The core trick is a clean ratio: 3 bytes in, 4 characters out.

  1. Take the input 3 bytes (24 bits) at a time.
  2. Split those 24 bits into four 6-bit groups.
  3. Each 6-bit group is a number from 0 to 63 — look it up in the 64-character alphabet.

Six bits encode exactly 64 possibilities, which is why the alphabet has 64 symbols. Worked example for the text Man:

Man
ASCII7797110
Binary010011010110000101101110
Regroup (6-bit)010011010110000101
Value19225
Base64 charTWF

So Man becomes TWFu. When the input length is not a multiple of 3, the final group is filled out and one or two = padding characters mark how many bytes were real.

Why does Base64 increase size by ~33%?

Because 3 bytes become 4 characters, the output is always about 4/3 (33%) larger than the input, before padding. That overhead is unavoidable and is the main reason you should not Base64-encode large payloads unless the channel truly requires text.

Input bytesBase64 charactersOverhead
3433%
10013636%
1,0001,33634%

Standard vs. URL-safe Base64

Two characters in the standard alphabet — + and / — are problematic inside URLs and filenames, where they have special meaning. Base64URL fixes this:

FeatureStandard Base64URL-safe (Base64URL)
62nd char+-
63rd char/_
Padding= keptusually dropped
Used inEmail, data URIsURLs, JWTs, filenames

This is exactly the alphabet used by JWTs — every part of a token is Base64URL-encoded JSON, which is why our how to decode a JWT guide leans on the same mechanics.

When should you use Base64?

Reach for Base64 when binary must travel through a text-only channel:

When should you not use Base64?

Common gotchas

Sources

Frequently asked questions

Is Base64 a form of encryption?

No. Base64 is reversible encoding with no key, so anyone can decode it instantly. It provides zero confidentiality. Use it to make binary data text-safe, never to protect a secret — for that you need encryption.

Why does Base64 make data bigger?

Base64 represents every 3 bytes of input as 4 ASCII characters, a 4:3 ratio, so encoded output is roughly 33% larger than the original, plus a little padding. That overhead is the price of being text-safe.

What is the difference between standard and URL-safe Base64?

Standard Base64 uses + and / and pads with =. URL-safe Base64 (Base64URL) replaces + with - and / with _ and usually drops the = padding, so the value can sit in a URL, filename, or JWT without escaping.

What are the = signs at the end of Base64?

They are padding. Because Base64 works in 4-character groups, when the input length is not a multiple of 3 the last group is padded with one or two = characters so the output length is a multiple of four.

Related articles

Last updated: 2026-06-14