Base64 to Hex Converter
Paste Base64 and get the hex bytes instantly. URL-safe Base64, missing = signs and data URLs all work, and the tool tells you if the data is an image, a PDF or plain text. Switch direction to turn hex into Base64.
4 Base64 characters = 3 bytes = 6 hex digits
48 65 6c 6c 6f 20 77 6f 72 6c 64
11 bytes · reads as text: “Hello world”
Everything runs in your browser; nothing is uploaded.
How to Convert Base64 to Hex
Base64 and hex are two ways of writing the same bytes as text. Base64 is shorter, so APIs, emails and web pages use it. Hex shows every byte as two characters, which makes it easier to read and compare. To convert, you turn the Base64 back into bytes and write each byte in hex:
- Look up the number (0 to 63) for each Base64 character in the table below.
- Write each number as 6 bits and join them all together.
- Cut the bits into groups of 8. Each group is one byte. Ignore any
=signs at the end. - Write each byte as two hex digits: the first 4 bits make the first digit, the last 4 bits make the second.
| Characters | Numbers | Bits |
|---|---|---|
| A to Z | 0–25 | 000000–011001 |
| a to z | 26–51 | 011010–110011 |
| 0 to 9 | 52–61 | 110100–111101 |
| + (or - in URL-safe Base64) | 62 | 111110 |
| / (or _ in URL-safe Base64) | 63 | 111111 |
| = (padding) | no value | – |
Worked Example: Q2F0 to Hex
Q2F0 is the word "Cat" in Base64. Four characters with no = means exactly three bytes.
Step 1: Look up each character
Step 2: Write each number as 6 bits
Step 3: Regroup the 24 bits into three bytes
Step 4: Write each byte as two hex digits
Result: 43 61 74, which are the letters C, a and t. Paste Q2F0 into the tool to check it.
Base64 to Hex Chart
The = signs tell you how many bytes the last group holds: == means 1 byte, = means 2, and none means 3.
| Base64 | Bytes | Hex |
|---|---|---|
| AA== | 1 | 00 |
| /w== | 1 | ff |
| AAA= | 2 | 00 00 |
| //8= | 2 | ff ff |
| AAAA | 3 | 00 00 00 |
| //// | 3 | ff ff ff |
| SGk= ("Hi") | 2 | 48 69 |
| Q2F0 ("Cat") | 3 | 43 61 74 |
| SGVsbG8= ("Hello") | 5 | 48 65 6c 6c 6f |
| 3q2+7w== | 4 | de ad be ef |
Why Does My Hex Look Wrong?
The most common mix-up is converting the Base64 letters to hex instead of decoding them. That gives the hex of the characters you typed: Q2F0 becomes 51 32 46 30 rather than 43 61 74. If another tool gives you about one and a third times as many bytes as this page, that is usually what happened.
| Problem | What to do |
|---|---|
| The string has - and _ in it | It is URL-safe Base64, used in web links and login tokens. Paste it as it is; this tool reads both kinds. |
| The = signs at the end are missing | Fine here. Some decoders insist on them, so add = until the length divides by 4. |
| It starts with data:image/png;base64, | That is a data URL. Paste the whole thing; the prefix is removed and the image type shown. |
| It is split over several lines | Line breaks and spaces are ignored. |
| It contains %3D or %2B | It was copied from a web address. Change %3D to =, %2B to + and %2F to / first. |
What Is This Base64? Spotting Images and Files
Most file types start with the same few bytes, so their Base64 always starts with the same few characters. That is a quick way to tell what a long Base64 string is. The tool checks this for you and names the file type under the result. If the bytes are ordinary text, it shows the text instead.
| File type | Base64 starts with | Hex starts with |
|---|---|---|
| PNG image | iVBORw0KGgo | 89 50 4E 47 |
| JPEG photo | /9j/ | FF D8 FF |
| GIF image | R0lGOD | 47 49 46 38 |
| PDF document | JVBERi0 | 25 50 44 46 |
| ZIP, Word or Excel file | UEsDB | 50 4B 03 04 |
| JSON text (e.g. a login token) | eyJ | 7B 22 |
To turn an image into Base64 in the first place, use the image to Base64 converter.
Base64 to Hex in Python, JavaScript and Other Languages
In code it is the same two steps: decode the Base64 to bytes, then print the bytes as hex. Each line turns SGVsbG8= into 48656c6c6f.
| Language | Code |
|---|---|
| Python | base64.b64decode(s).hex() |
| JavaScript (Node.js) | Buffer.from(s, 'base64').toString('hex') |
| JavaScript (recent browsers) | Uint8Array.fromBase64(s).toHex() |
| Java (17+) | HexFormat.of().formatHex(Base64.getDecoder().decode(s)) |
| C# (.NET 5+) | Convert.ToHexString(Convert.FromBase64String(s)) |
| PHP | bin2hex(base64_decode($s)) |
| Mac or Linux terminal | echo 'SGVsbG8=' | base64 -d | xxd -p |
For URL-safe Base64 (with - and _), use the URL-safe decoder: urlsafe_b64decode in Python or getUrlDecoder() in Java. Going the other way? See the hex to Base64 converter.
Frequently asked questions
Why is the hex longer than the Base64?
Hex uses 2 characters for every byte, while Base64 uses 4 characters for every 3 bytes. So 24 Base64 characters (18 bytes) become 36 hex digits.
Does uppercase or lowercase hex matter?
No. DE and de are the same byte. Use the ABC button to match whatever you are comparing against.
How do I get the original file back instead of hex?
Decode straight to a file: base64 -d input.txt > file.bin on Mac or Linux, or certutil -decode input.txt file.bin on Windows. Hex is for looking at the bytes, not saving them.
Is decoding Base64 the same as decrypting it?
No. Base64 is just a way of writing bytes as text, and anyone can reverse it without a key. If the hex looks random, the bytes may be encrypted or compressed underneath.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings: the Base64 and URL-safe alphabets and = padding.
- MDN: Base64: how Base64 is used on the web and in data URLs.
Related Tools
Convert hexadecimal values into Base64 encoded data.
Convert binary values into hexadecimal numbers.
Convert CMYK color values into HEX color codes.
Convert HEX color codes into CMYK color values.
Convert decimal integers into hexadecimal values.
Convert hexadecimal values into decimal integers.