toolfree

Base64 encoder and decoder

Encode text to Base64 and decode it back, with correct UTF-8 handling for Chinese and emoji. URL-safe alphabet supported. Runs in your browser.

Runs in your browser

What Base64 is for

Base64 rewrites arbitrary bytes using 64 characters that survive systems designed for text: email bodies, JSON strings, URLs, HTML attributes. It is an encoding, not encryption — anyone can decode it, and the decoded value is the original exactly. Never use it to hide anything.

The cost is size. Every 3 bytes become 4 characters, so encoded data is about 33% larger than what went in.

UTF-8 is where most tools go wrong

The browser’s own btoa works on Latin-1 code units, so it throws outright on 你好 and mangles anything above U+00FF. Correct encoding converts text to UTF-8 bytes first:

// Wrong: throws on any non-Latin-1 character
btoa('你好')

// Right
btoa(String.fromCharCode(...new TextEncoder().encode('你好')))

The converter above does this in both directions, so Chinese, Japanese, and emoji round trip intact. A decode that produces mojibake here means the input was not UTF-8 text to begin with — often it was a binary file, not text at all.

Standard and URL-safe alphabets

Both alphabets encode the same bytes; only three characters differ.

Character 62Character 63Padding
Standard (RFC 4648 §4)+/=
URL-safe (RFC 4648 §5)-_usually dropped

+ becomes a space when a URL query string is parsed, and / breaks path segments, which is why JWTs and signed URLs use the URL-safe form with padding stripped. The decoder accepts either, with or without padding.

Data URIs

A data URI is Base64 with a media type in front of it, letting a small image or font live inside a stylesheet or HTML file rather than in a separate request:

data:image/png;base64,iVBORw0KGgo…

This is worth it only for genuinely small assets — the 33% overhead is paid on every page load and the bytes cannot be cached separately.

Your data stays here

Encoding and decoding happen in your browser. Nothing you paste is uploaded — worth knowing, since Base64 blobs pasted into online decoders are frequently tokens and session cookies.