What Is Base64?

Base64 is an encoding that rewrites binary data using only 64 printable ASCII characters. Three input bytes become four output characters, so the data grows by about 33 percent. It exists so that files and images can travel through systems that only accept text — email, JSON fields, URLs, config files. It is not encryption: anyone who sees a Base64 string can turn it back into the original bytes without a key.

  • Three bytes in, four characters out — roughly 33 percent larger
  • The alphabet is A-Z a-z 0-9 + /, with = used only as padding at the end
  • Reversible by anyone: no key, no password, no secret
  • Standard Base64 is not URL-safe; the URL variant swaps + and / for - and _
  • Paste a string into the tool above to see the original bytes or text
b64file — converter · local

Processed as you paste — no button to press (Ctrl+Enter converts now / Esc clears)

Paste, drag and drop, or Ctrl+V a screenshot

[01]

The problem it solves

Old mail protocols were designed for seven-bit ASCII. A single byte with the high bit set — anything from an image, a compressed archive, a PDF — could be corrupted or stripped by a mail server that was never built to carry it. Base64 was the workaround: map every possible byte value into a subset of characters that every system on the path already agrees on.

The same constraint shows up today in places that are not email at all. A JSON body has to be valid text, so an API that accepts a file as a field encodes it first. A URL cannot carry arbitrary bytes safely, so signed parameters and tokens are encoded. A YAML file inside a Kubernetes manifest holds TLS material as Base64 so it stays one text value. None of these systems need secrecy — they need a form that survives copying.

[02]

How the mapping works

Take three bytes — 24 bits. Split them into four groups of six bits. Six bits gives 64 possible values, and 64 printable characters is exactly what the alphabet provides. So three bytes map onto four characters, and the decoder reverses it without ambiguity.

A concrete example. The word Man is the bytes 4D 61 6E, or in binary 01001101 01100001 01101110. Regrouped into sixes: 010011 010110 000110 101110 — that is 19, 22, 5, 46. In the standard alphabet those are T, W, F, u, so the encoded form is TWFu.

Only the last group is ever incomplete. Ma is two bytes, 16 bits — enough for two full six-bit groups and a partial third. The encoder pads the missing positions with zero bits and marks how many bytes were missing with =, giving TWE=. A single byte becomes TQ==. That is why the length of a Base64 string is always a multiple of four, and why the number of trailing = tells you how much padding was added — a fact that makes truncated data easy to spot.

[03]

Why the output is about 33 percent larger

Four characters for every three bytes is a ratio of 4/3, so encoded data is 33 percent bigger than the input. A 3 MB PDF becomes roughly 4 MB of text. That growth is paid again wherever the string is copied: in the request body, in memory, in a database column, in a log line.

This is the usual reason an upload fails with a size error even though the file itself is under the limit. The API limit applies to the encoded string, not the file. If you control both ends, send the file as multipart form data and skip the encoding entirely.

[04]

The variant most people trip over

Standard Base64 uses + and /. Both are meaningful inside a URL: + is read as a space in query strings, and / is a path separator. The URL-safe variant (Base64URL, defined in RFC 4648) replaces them with - and _, and usually drops the padding entirely. JWTs use this variant for all three segments.

Mixing the two is the most common decoding failure there is: a string that looks perfectly valid but throws an error because it contains - where the standard decoder expects +. If a string refuses to decode, convert the alphabet first — see Base64URL.

[05]

What Base64 is not

It is not encryption. There is no key, no nonce, no secret — the transformation is fixed and public. Anyone can decode a string in a browser console in one line. It is not compression either: it always makes data bigger, never smaller. And it is not a hash: a hash is one-way and fixed-length, while Base64 is fully reversible and keeps the original size relationship.

Those distinctions matter in practice, because "it looks like gibberish" is not evidence of protection. If the data is a credential, a token or a private document, encoding it changes nothing about who can read it — see Base64 vs encryption.

Frequently asked questions

Can Base64 be decoded without the original key?

There is no key. Decoding needs only the alphabet and the padding rules, which are public. Treat any Base64 string as readable by anyone who receives it.

Why does my string end with = or ==?

Padding. Two bytes of input leave one character short of a group of four and get =; one byte leaves two short and gets ==. If the input length is an exact multiple of three, there is no padding at all.

Is Base64 the same in every language?

The standard alphabet is. Implementations differ on how forgiving they are: most browsers and Node strip whitespace and accept missing padding, while stricter decoders reject both. When a string fails in one place and works in another, look at whitespace and padding first.

How large a file can I encode in a browser?

There is no fixed limit, but browser string handling gets expensive above a few megabytes and pointless above tens of megabytes. For anything large, encode in a worker, or send the file as multipart data instead.

Related tools and guides