Ctrl K

Base64 Explained: What It Is and When to Use It

beginner TheToolSera Team 7 min read Updated 25 May 2026

Base64 solves one problem: moving binary data through channels that only accept text. It is everywhere — email attachments, data URLs, JWTs, API keys, certificates — and it is routinely misunderstood as a form of security.

How the encoding works

Base64 takes three bytes (24 bits) and re-slices them into four 6-bit groups. Each group indexes an alphabet of 64 printable characters: A–Z, a–z, 0–9, plus and slash. Because every output character is safe ASCII, the result survives systems that would mangle raw bytes.

Encoding the word "Sun"
Text      S        u        n
ASCII     83       117      110
Bits      010100 11 0111 0101 101110
6-bit     010100   110111   010110   1110xx -> regrouped
Base64    U        3        V        u

When the input length is not a multiple of three, the final group is padded with one or two = characters. That is all the trailing equals signs mean — they carry no data.

Why output is 33% larger

Four output characters represent three input bytes, so size grows by exactly 4/3, plus padding. A 3 MB image becomes about 4 MB of Base64 text. That overhead is the price of text safety, and it is the main reason not to inline large assets as data URLs.

Where you will encounter it

  • Data URLs: data:image/png;base64,iVBORw0KGgo…
  • HTTP Basic authentication headers
  • MIME email attachments
  • JWT headers and payloads (Base64URL, not standard Base64)
  • PEM certificates and keys between the BEGIN and END lines
  • Binary blobs squeezed into JSON, which has no binary type

Base64 vs Base64URL

Standard Base64 uses + and /, which have meaning inside URLs and file paths. The URL-safe variant substitutes - and _ and usually drops the padding. JWTs use this variant, which is why a JWT segment pasted into a plain Base64 decoder sometimes fails.

AspectBase64Base64URL
Index 62+-
Index 63/_
Padding= requiredUsually omitted
Used byMIME, PEM, data URLsJWT, OAuth, query parameters

Base64 is not encryption. It is a reversible, keyless transformation that anyone can decode instantly. Never use it to hide passwords, tokens or personal data.

Encoding and decoding in code

JavaScript — Unicode-safe round trip
// btoa/atob only handle Latin-1, so encode to UTF-8 bytes first
const toBase64 = (str) =>
  btoa(String.fromCharCode(...new TextEncoder().encode(str)));

const fromBase64 = (b64) =>
  new TextDecoder().decode(
    Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
  );

toBase64("café"); // "Y2Fmw6k="
Python and the shell
import base64
base64.b64encode(b"Sun")          # b'U3Vu'
base64.urlsafe_b64decode(token + "==")

# shell
echo -n "Sun" | base64
echo "U3Vu" | base64 --decode

Base64 Encoder

Encode or decode text and files instantly — nothing is uploaded.

Try Base64 Encoder

Common mistakes

Using btoa on Unicode text

btoa throws on characters above U+00FF. Convert to UTF-8 bytes with TextEncoder first.

Treating Base64 as security

Encoded credentials in a header or config file are plaintext for practical purposes.

Inlining large images as data URLs

You add 33% size, block caching and bloat the HTML. Inline only tiny icons.

Forgetting the data URL prefix

Decoders choke on "data:image/png;base64," — strip everything up to and including the comma.

Mixing the two alphabets

A JWT segment needs Base64URL decoding, and padding may need to be re-added before decoding.

If you are decoding a token rather than a plain blob, a dedicated JWT decoder splits the three segments and parses the JSON for you.

Frequently asked questions

Is Base64 encryption?

No. It is an encoding with no key. Anyone can decode it in one step, so it provides zero confidentiality.

Why does Base64 end with = signs?

Padding. They make the output length a multiple of four when the input is not a multiple of three bytes.

How much larger is Base64 data?

About 33% — four output characters for every three input bytes, plus up to two padding characters.

Why does my Base64 string fail to decode?

Common causes are a data URL prefix, Base64URL characters (- and _), stripped padding, or whitespace and line breaks inside the string.

Put this into practice

Base64 Encoder runs entirely in your browser — no upload, no account, no limits.

Open Base64 Encoder

Related tools

Related guides

All guides

Explore related topics