Base64 encode & decode

Convert text or files to Base64 and back. If a string is broken, you’ll see exactly where, what it decodes to anyway, and a one-click fix. All in your browser.

Text
Base64
Ready

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-safe

Python:

import base64
base64.b64encode(b'hello')           # b'aGVsbG8='
base64.urlsafe_b64encode(b'hello')   # URL-safe

Command line:

echo -n 'hello' | base64          # aGVsbG8=
echo 'aGVsbG8=' | base64 --decode   # hello

Data 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?
No. Base64 is an encoding, not encryption. Anyone can decode it instantly, so never use it to hide passwords or secrets.
Why is Base64 bigger than the original?
It uses 4 characters for every 3 bytes, so output is about 33% larger, plus up to two = padding characters.
What is URL-safe Base64?
Standard Base64 uses + 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?
Usually one of four things: a character that isn’t Base64 (often a quote or space picked up while copying), a string cut off part-way, two strings glued together, or Base64 that was URL-encoded (%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?
The data probably isn’t text. It might be an image, a compressed file or encrypted bytes. This tool spots that and shows a hex dump instead, with a preview for common image formats and a button to download the file.
Does it handle emoji and accents?
Yes. Text is encoded as UTF-8 first, so café 👋 round-trips correctly. That’s something the browser’s built-in btoa() can’t do on its own.
↑↓ move↵ openesc close