How to decode Base64
- Paste the Base64 into the Input · Base64 box. Line breaks, spaces, surrounding quotes and a
data:...;base64,prefix can stay; the decoder removes them. - The decoded text appears in Output · text. A status line reports Valid Base64, the variant (Standard or Base64URL), the number of decoded bytes and, under Looks like, the detected content type.
- If the text is garbled, change Charset, or choose Auto-detect.
- If the content is JSON, Pretty-print JSON indents it for reading.
- Press Copy output, or Download to save the decoded bytes as a file. The extension follows the detected type, so JSON is saved as
decoded.jsonand a PNG asdecoded.png.
Swap sends decoded text back to the input and switches to encoding, which is a quick way to confirm the string round-trips.
What the decoder accepts
Base64 rarely arrives clean. It comes wrapped at 76 characters from an email, quoted from a JSON file, percent-encoded from a URL or without its padding from a token. The decoder accepts all of these without any setting:
| You paste | You get | What happened |
|---|---|---|
SGVsbG8gV29ybGQ | Hello World | Missing = restored, the status line says so |
8J-Riw | 👋 | URL-safe - and _ recognized, variant shown as Base64URL |
data:text/plain;base64,SGk= | Hi | Data URI prefix removed |
"SGVsbG8=" | Hello | Quotes from code or JSON removed |
SGVsbG8%3D | Hello | URL-encoded %3D read as = |
SGVs (new line) bG8= | Hello | Line breaks and spaces skipped |
The decoder is lenient about this packaging and strict about everything else: a character outside the alphabet stops it, with an error naming the character and its position. Some libraries silently skip bad characters and hand you corrupted output (see the code section below).
For URL-safe tokens specifically, the Base64URL decoder explains the alphabet and Base64 vs Base64URL the differences.
When the decoded Base64 is a file
Base64 carries any bytes, and many Base64 strings are images or documents. The tool checks the first bytes of the decoded data against known file signatures (magic numbers) and shows the result as Looks like: PNG, JPEG, PDF, ZIP, gzip, JSON, XML and many more. For binary formats it shows a printable preview, says the data is binary and links to the right tool, such as Base64 to image or Base64 to PDF. Download saves the original bytes either way.
The start of a Base64 string often gives the format away before you decode it:
| Base64 starts with | Decoded bytes | Format |
|---|---|---|
iVBORw0KGgo | 89 50 4E 47 0D 0A 1A 0A | PNG image |
/9j/ | FF D8 FF | JPEG image |
JVBERi0 | %PDF- | PDF document |
UEsDBA | PK 03 04 | ZIP, also DOCX and XLSX |
H4sI | 1F 8B 08 | gzip data (gzip Base64 decoder) |
eyJ | {" | JSON, often a JWT segment |
PD94bWwg | <?xml | XML |
More signatures are listed in common Base64 prefixes. For a file of unknown type, Base64 to file detects the format and previews it.
Charsets: fixing garbled text
Base64 stores bytes and says nothing about which charset turned characters into those bytes. The decoder assumes UTF-8, which is right for most modern data. When it is wrong, the symptoms are recognizable:
�characters and the note “Some bytes are not valid UTF-8”. The text came from a legacy charset.Y2Fm6Q==reads ascaf�in UTF-8 and ascaféin ISO-8859-1 or Windows-1252. Russian text such asz/Do4uXyneeds Windows-1251 to showПривет.- A dot or gap after every letter. That is UTF-16, where ASCII letters are followed by a zero byte.
SABlAGwAbABvAA==isHelloin UTF-16LE (Base64 to UTF-16). é,üor’in the output. The decoding is correct; the text was double-encoded before it was turned into Base64, because some earlier step misread UTF-8 as Latin-1 and stored the result as UTF-8 again.Y2Fmw4PCqQ==decodes to exactlycafé. Fix it at the source.
Auto-detect checks for a byte order mark, then whether the bytes are valid UTF-8, then for the zero-byte pattern of UTF-16. Single-byte code pages such as Windows-1251 and KOI8-R look alike to any detector, so pick those by hand when you know the source.
Error messages and what they mean
| Message | Usual cause | Fix |
|---|---|---|
| Invalid character “.” at position 21 | A whole JWT pasted: the dots separate three segments | Decode one segment, or use the JWT decoder |
Invalid character "\\" at position 8 | Base64 copied from JSON where / was escaped as \/ | Replace \/ with / |
| The input mixes standard (+ /) and URL-safe (- _) characters | Two strings joined, or a half-done conversion | Convert to one alphabet with Base64URL to Base64 |
| Padding (=) can only appear at the very end | Two Base64 values glued together, like SGk=SGk= | Split them and decode each |
| Wrong length: one character too many or too few | The copy lost or gained a character | Recopy, or try Repair Base64 |
The Base64 errors guide goes through each case in more depth. To find the exact character or padding problem in a string, use the Base64 validator.
Base64 decode in JavaScript, Python and the command line
atob() returns a “binary string” with one character per byte, so UTF-8 text needs a TextDecoder step. atob accepts missing padding but throws InvalidCharacterError on URL-safe - and _.
const s = "R3LDvMOfZSDwn5GL";
new TextDecoder().decode(Uint8Array.from(atob(s), c => c.charCodeAt(0)));
// "Grüße 👋"
// Node.js accepts both alphabets
Buffer.from(s, "base64").toString("utf8"); // "Grüße 👋"
Buffer.from("8J-Riw", "base64url").toString("utf8"); // "👋"
Python raises binascii.Error: Incorrect padding on unpadded input, so add the padding yourself:
import base64
s = "SGVsbG8"
base64.b64decode(s + "=" * (-len(s) % 4)).decode("utf-8")
# 'Hello'
base64.b64decode("SGVs*bG8=", validate=True)
# binascii.Error: Only base64 data is allowed
Without validate=True, Python discards the * and returns b'Hello'. Node’s Buffer.from behaves the same way, so a damaged string can decode without any error.
On the command line:
printf '%s' 'R3LDvMOfZSDwn5GL' | base64 -d
base64 -d message.b64 > message.bin
The first line prints Grüße 👋. Older macOS versions spell the flag -D. More detail per language: JavaScript, Node.js, Python, PHP.
FAQ
How do I decode a Base64 string?
Paste it into the input box above; the decoded text appears immediately. In code, decode the Base64 to bytes and then read the bytes as UTF-8: base64.b64decode(s).decode() in Python, Buffer.from(s, "base64").toString() in Node.js.
Why does my decoded text show strange characters like � or é?
� means the bytes are not valid UTF-8, so the text was probably encoded in another charset; try Windows-1252, Windows-1251 or UTF-16LE in the Charset menu. é in place of é means the text was already garbled before someone encoded it.
Can I decode Base64 without the = padding?
Yes. The decoder adds the missing = itself and says so in the status line. Padding only fills the last block, so it can always be restored from the length.
The decoded output is gibberish. Is the Base64 broken?
More often the data is a file. Check the “Looks like” field in the status line: for images, PDFs, archives and other binary formats the tool links to a decoder that previews or saves the file.
Can Base64 be decoded without a key?
Always. Base64 is an encoding with a public alphabet, so it offers no secrecy. If the decoded result still looks random, the data was encrypted or compressed before it was encoded.