encode / base64

Base64 Encoder & Decoder

Encode text to Base64 or decode it back, with a URL-safe option for tokens and query strings. Full Unicode support, and nothing leaves your browser.

~/encode/base64unicode safe
Plain text
Base64
reference

What Base64 is for

Base64 turns arbitrary bytes into 64 safe ASCII characters (A–Z, a–z, 0–9, plus two symbols). It exists so binary data can travel through channels that only expect text — data URIs in CSS, image bytes inside JSON, email attachments, basic-auth headers. The trade-off is size: the output is about 33% larger than the input.

Variant62nd / 63rd charPaddingUse
Standard+ /=Email, data URIs, general data
URL-safe- _usually droppedJWTs, URLs, filenames

Gotcha — Base64 is not encryption. Anyone can decode it instantly; it hides nothing. It is encoding, not security and not compression. Never use it to "protect" passwords or secrets — use real hashing or encryption for that.

how it works

Turning bytes into characters

Base64 reads data three bytes (24 bits) at a time and re-slices those 24 bits into four 6-bit groups. Six bits can hold 64 values, so each group maps to one character of the alphabet. Three bytes in always become four characters out — which is where the roughly one-third size increase comes from. When the input is not a multiple of three bytes, the encoder adds one or two = signs as padding; URL-safe Base64 usually drops them.

A worked example

The three letters Cat are the byte values 67 97 116 (decimal) — that is 0x43 0x61 0x74 in hex. As bits: 01000011 01100001 01110100. Regroup into four 6-bit chunks — 010000 110110 000101 110100 — giving indexes 16, 54, 5 and 52, which are Q, 2, F and 0. So Cat encodes to Q2F0.

in code

Encoding Base64 in different languages

The runtime usually has this built in. Note the JavaScript line: bare btoa only handles Latin-1, so the encodeURIComponent wrapper is what lets Unicode survive — the same approach this tool uses.

// JavaScript (browser) — Unicode-safe
const b64 = btoa(unescape(encodeURIComponent("héllo")));
const txt = decodeURIComponent(escape(atob(b64)));

# Python 3
import base64
base64.b64encode("héllo".encode()).decode()
base64.b64decode(b64).decode()

# Command line
echo -n "héllo" | base64
echo -n "aMOpbGxv" | base64 --decode

One practical snag: classic MIME/email Base64 wraps lines every 76 characters. If a decoder rejects such a block, strip the newlines first — this tool ignores whitespace on decode, so wrapped input still works.

when to use it

Good and bad uses

data URIs

When inlining with Base64 actually pays off

The tempting trick is to drop an image straight into your CSS or HTML as a data: URI and save an HTTP request. Sometimes that is the right call, often it isn't, and the deciding factor is size. A 1 KB SVG icon or a tiny background pattern inlines beautifully: no extra round trip, no separate cache entry to manage, and the 33% Base64 overhead on something that small is noise. A 400 KB hero photo is the opposite story. Inlined, it now weighs about 530 KB, it can't be cached on its own, it can't load lazily, and it bloats the very HTML or stylesheet the browser needs first to render the page. As a rough line in the sand, inline assets under a few kilobytes and link to anything bigger.

There's also a flavour to get right. JWTs, anything that travels in a URL, and most modern APIs use Base64url, which swaps + and / for - and _ and usually drops the = padding, because a raw + or / would be mangled in a query string. Standard Base64 is fine for email attachments and JSON bodies. Feed standard Base64 where URL-safe is expected and you'll get intermittent, maddening failures that only show up when the data happens to contain a + or /.

faq
What's the difference between Base64 and Base64url?

Base64url replaces the two characters that break URLs, + and /, with - and _, and typically omits the trailing = padding. Use it for tokens, query strings and JWTs; standard Base64 is fine for email and JSON.

Why is Base64 about a third larger than the original?

It represents every 3 bytes with 4 ASCII characters, so the output grows by roughly 33%. That overhead is the price of moving binary safely through text-only channels.

What do the = signs at the end mean?

Padding. When the input is not a multiple of three bytes, one or two = round the output to a multiple of four. URL-safe Base64 usually omits them.

Does it handle emoji and non-English text?

Yes. The text is read as UTF-8 before encoding, so accents, CJK characters and emoji round-trip correctly.

When should I tick URL-safe?

When the Base64 will sit in a URL, query string, cookie or filename. It swaps + and / (which have meaning in URLs) for - and _, and drops the = padding.

Is my input uploaded?

No. Encoding and decoding use the browser's built-in functions; your data never leaves the page.