How to convert Base64 to hex
- Paste the Base64 into Input · Base64. Line breaks, spaces, missing
=padding and URL-safe characters are all accepted. - The bytes appear in Output · Hex. The status line shows Looks like with the detected file type, if the bytes match a known format.
- Under the output, choose Case, Separator and Bytes per line.
- Copy output or Download the hex. Save bytes writes the decoded bytes themselves as a file.
For the other direction, use the Hex → Base64 toggle or Hex to Base64.
Output options
The Base64 SGkh/w== holds four bytes. The Separator setting decides how they are written:
| Separator | Output | Use it for |
|---|---|---|
| None | 486921ff | comparing with sha256sum output, databases, URLs |
| Space | 48 69 21 ff | reading byte by byte, hex editors |
: | 48:69:21:ff | certificate and key fingerprints |
0x | 0x48 0x69 0x21 0xff | C, C# or Java constants |
\x | \x48\x69\x21\xff | string literals in Python, C and shell |
Case switches to 48 69 21 FF. Bytes per line set to 16 gives the familiar dump layout, 16 bytes to a row, which makes it easy to find offset 0x40 or count a header’s length.
Reading the first bytes
Most file formats start with a fixed signature, and in hex those signatures are easy to recognize. A few Base64 prefixes and what they decode to:
| Base64 starts with | Hex | Format |
|---|---|---|
iVBORw0KGgo | 89 50 4e 47 0d 0a 1a 0a | PNG |
/9j/ | ff d8 ff | JPEG |
JVBERi0 | 25 50 44 46 2d (%PDF-) | |
UEsDBA | 50 4b 03 04 (PK) | ZIP, and DOCX, XLSX, JAR, APK |
H4sI | 1f 8b 08 | gzip |
When the first bytes match none of these, they may still be text in an unexpected charset, or encrypted data, which looks uniformly random in hex. The list of common Base64 prefixes has many more. If the data turns out to be a file you want to open, Base64 to File previews and saves it.
Comparing digests and checksums
Hex is the format checksum tools print, so converting Base64 to hex is how you compare a value from a header or a config file with your own md5sum or sha256sum:
| Where you see it | Base64 | Hex |
|---|---|---|
Content-MD5 header for hello | XUFAKrxLKna5cZ2REBfFkg== | 5d41402abc4b2a76b9719d911017c592 |
SHA-256 of hello | LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ= | 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 |
The same applies to integrity="sha384-…" attributes, SSH fingerprints in SHA256: form (Base64 without padding) and binary keys in JSON. If two values differ in hex, they differ in bytes; if they match, any difference in the Base64 was only formatting, such as padding or the URL-safe alphabet.
Base64 to hex in code
import base64
base64.b64decode("SGkh/w==").hex() # '486921ff'
base64.b64decode("SGkh/w==").hex(" ") # '48 69 21 ff'
Buffer.from("SGkh/w==", "base64").toString("hex"); // '486921ff'
In Python, b64decode silently drops characters outside the alphabet unless you pass validate=True, so a URL-safe string can decode to the wrong bytes without an error. Node’s "base64" decoder accepts both alphabets. See the Python and Node.js pages for details.
FAQ
How do I decode Base64 to hex on Linux?
echo 'SGkh/w==' | base64 -d | xxd -p prints 486921ff. xxd -p breaks lines every 30 bytes; add -c 32 for 32 bytes per line, or use od -An -tx1 if xxd is not installed.
Why does my hex contain ef bf bd?
Those three bytes are the UTF-8 form of �, the replacement character. Some tool decoded the Base64 to text first and replaced every byte that was not valid UTF-8. Decode straight to hex, as this page does, and the original bytes come through.
How long is the hex compared to the Base64?
About 1.5 times as long. Four Base64 characters hold three bytes, which take six hex digits. A 44-character SHA-256 value becomes 64 hex digits.
Does it accept Base64URL and data URIs?
Yes. - and _ are read like + and /, missing padding is fine, and a data:...;base64, prefix is skipped.