What is Base64?
Base64 turns any binary data into plain text using 64 safe characters: A–Z, a–z, 0–9, + and /. It’s used wherever binary data has to travel through something built for text, such as email attachments, JSON payloads, data URIs, HTTP Basic auth and JWTs.
Every 3 bytes (24 bits) become 4 characters of 6 bits each. If the input isn’t a multiple of 3 bytes, = pads the end.
"Man" → 01001101 01100001 01101110
→ 010011 010110 000101 101110
→ T W F u → "TWFu"When Base64 won’t decode
Most decoders just say “invalid input”. This one marks the problem in the input, explains it, and still shows you as much of the decoded result as it can.
- Stray characters such as quotes, commas or
*are marked and skipped. One click removes them. - Cut-off strings: Base64 comes in groups of 4, so a length that leaves 1 character over means the end got lost while copying.
- Two strings joined together show up as
=in the middle. Each part is decoded separately so you can see both. - URL-encoded Base64 from a query string (
%3D,%2B,%2F) is URL-decoded first. - A “Basic ” prefix or surrounding quotes are ignored, so you can paste an Authorization header as it is.
- Mixed alphabets: standard (
+ /) and URL-safe (- _) characters in one string are converted to one or the other. - It’s really a JWT or JSON: you get a link that opens it in the JWT decoder or JSON formatter.
If the result isn’t text, you get a hex dump and a Download button instead of a screen of garbage.
Base64 in code
Browser JavaScript (UTF-8 safe):
// encode
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode(text)));
// decode
const text = new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)));Node.js:
Buffer.from('hello').toString('base64') // 'aGVsbG8='
Buffer.from('aGVsbG8=', 'base64').toString() // 'hello'
Buffer.from('hello').toString('base64url') // URL-safePython:
import base64
base64.b64encode(b'hello') # b'aGVsbG8='
base64.urlsafe_b64encode(b'hello') # URL-safeCommand line:
echo -n 'hello' | base64 # aGVsbG8=
echo 'aGVsbG8=' | base64 --decode # helloData URIs
Tick “Data URI” to get a string you can drop straight into HTML or CSS:
<img src="data:image/png;base64,iVBORw0KGgo..." />It’s handy for tiny icons, but remember the 33% size overhead, and that inlined images can’t be cached separately.
Encoding something for a URL rather than a payload? Use the URL encoder instead.
Questions people ask
Is Base64 encryption?
Why is Base64 bigger than the original?
= padding characters.What is URL-safe Base64?
+ and /, which have special meanings in URLs. URL-safe Base64 (also called base64url) swaps them for - and _ and usually drops the = padding. JWTs use it.Why won’t my Base64 decode?
%3D instead of =). This tool marks the exact spot, decodes what it can anyway, and offers a one-click fix.Why does my decoded text look garbled?
Does it handle emoji and accents?
café 👋 round-trips correctly. That’s something the browser’s built-in btoa() can’t do on its own.