Hex to Base64 Converter
Paste hex and get Base64 instantly. Works for hashes, checksums and any hex bytes, written with or without spaces, colons or 0x in front. Switch direction to decode Base64 to hex.
6 hex digits = 3 bytes = 4 Base64 characters
SGVsbG8=
5 bytes read from spaced hex → 8 characters
Everything runs in your browser; nothing is uploaded.
How to Convert Hex to Base64
Hex and Base64 are two ways of writing the same bytes as text. Hex uses 2 characters per byte. Base64 uses 4 characters for every 3 bytes, so it is a third shorter. You don't convert the letters directly: you turn the hex back into bytes, then write those bytes in Base64.
- Read the hex two digits at a time. Each pair is one byte (00 to FF).
- Take the bytes three at a time and write them out as 24 bits.
- Cut the 24 bits into four groups of 6. Each group is a number from 0 to 63.
- Look each number up: A–Z are 0–25, a–z are 26–51, 0–9 are 52–61, then + is 62 and / is 63.
If one or two bytes are left over at the end, fill the missing bits with zeros and add an = for each missing character. You can paste hex with spaces, colons, line breaks or 0x in front; the tool ignores them.
Worked Example: 48 65 6C 6C 6F to SGVsbG8=
The hex 48 65 6C 6C 6F is the word "Hello". Five bytes make one full group of three, with two bytes left over.
Step 1: Write the first three bytes, 48 65 6C, as bits
Step 2: Regroup into sixes and look each one up
Step 3: Do the last two bytes, 6C 6F, filling with zeros
Result: SGVsbG8=, 8 characters for 5 bytes. Paste 48 65 6C 6C 6F into the tool to check it.
Hex to Base64 Chart
The = signs follow the byte count: 1 byte left over ends in ==, 2 bytes in =, and a full group of 3 in nothing.
| Hex | Bytes | Base64 |
|---|---|---|
| 00 | 1 | AA== |
| FF | 1 | /w== |
| 00 00 | 2 | AAA= |
| FF FF | 2 | //8= |
| 00 00 00 | 3 | AAAA |
| FF FF FF | 3 | //// |
| 48 69 ("Hi") | 2 | SGk= |
| 48 65 6C 6C 6F ("Hello") | 5 | SGVsbG8= |
| DE AD BE EF | 4 | 3q2+7w== |
| 01 02 03 04 05 | 5 | AQIDBAU= |
Why Is My Base64 Different From Another Tool's?
Usually the other tool encoded the hex characters instead of the bytes they stand for. The result is still valid Base64, just of the wrong thing, and it comes out about twice as long. It is easy to do by accident in a terminal:
| Command | Output |
|---|---|
echo 48656c6c6f | base64 (wrong) | NDg2NTZjNmM2Zgo= |
echo 48656c6c6f | xxd -r -p | base64 (right) | SGVsbG8= |
If the lengths match but a few characters differ, check the output option. URL-safe Base64 swaps + and / for - and _ and leaves off the = signs. PEM and MIME add line breaks. The bytes are the same in all of them.
Converting a Hash or Checksum to Base64
The most common reason to convert hex to Base64 is a hash. Checksum tools print hashes in hex, but many websites and APIs ask for the same hash in Base64. The hash doesn't change, only how it's written. For example, the MD5 of an empty file is d41d8cd98f00b204e9800998ecf8427e in hex and 1B2M2Y8AsgTpgAmY7PhCfg== in Base64. The tool tells you when a pasted value is the size of a common hash.
| Hash | Bytes | Hex digits | Base64 characters |
|---|---|---|---|
| MD5 | 16 | 32 | 24 (ends in ==) |
| SHA-1 | 20 | 40 | 28 (ends in =) |
| SHA-256 | 32 | 64 | 44 (ends in =) |
| SHA-512 | 64 | 128 | 88 (ends in ==) |
Hex to Base64 in Python, JavaScript and Other Languages
In code it is the same two steps: turn the hex into bytes, then Base64-encode the bytes. Each line turns 48656c6c6f into SGVsbG8=. Strip any spaces or 0x prefixes first.
| Language | Code |
|---|---|
| Python | base64.b64encode(bytes.fromhex(h)).decode() |
| JavaScript (Node.js) | Buffer.from(h, 'hex').toString('base64') |
| JavaScript (recent browsers) | Uint8Array.fromHex(h).toBase64() |
| Java (17+) | Base64.getEncoder().encodeToString(HexFormat.of().parseHex(h)) |
| C# (.NET 5+) | Convert.ToBase64String(Convert.FromHexString(h)) |
| PHP | base64_encode(hex2bin($h)) |
| Mac or Linux terminal | echo 48656c6c6f | xxd -r -p | base64 |
The mistake to avoid in any language is calling the Base64 function on the hex string itself. Going the other way? See the Base64 to hex converter.
Frequently asked questions
Why is the Base64 shorter than the hex?
Hex spends 2 characters on every byte, Base64 spends 4 characters on every 3 bytes. So 64 hex digits (32 bytes) become 44 Base64 characters.
How do I convert a hex number like 1F4?
Add a 0 in front to make an even number of digits: 01F4 is the bytes 01 F4, which encode to AfQ=.
Which output option should I use?
Standard for most uses. URL-safe for web addresses, file names and login tokens. PEM for certificate and key files, MIME for email.
Can I paste a checksum with the file name after it?
Paste only the hash. Letters outside a–f are rejected, but a file name made only of a–f letters, such as cafe, would be read as extra bytes.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings: the Base64 alphabet, 24-bit groups and = padding.
- MDN: Base64: how Base64 is used on the web.
Related Tools
Convert Base64 encoded data into hexadecimal values.
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.