How to use the Hex to Base64 tool
- Paste the hex digits into the Hexadecimal bytes box, or select Example to load 48 65 6c 6c 6f.
- Leave separators in place if you like. Spaces, line breaks, commas, colons, hyphens and 0x prefixes are removed automatically.
- Select Encode to parse the digits and convert the bytes.
- Read the Base64 string in the Result box and select Copy to put it on your clipboard.
How hex to Base64 conversion works
Hex and Base64 are two ways to write the same bytes. Hex spends one character on 4 bits, so a byte takes two characters. Base64 spends one character on 6 bits, so three bytes take four characters. Converting between them needs no character set: the tool turns each pair of hex digits into a byte, lines the bits up, cuts them into 6-bit groups and looks each group up in the RFC 4648 alphabet.
Because of that ratio, Base64 is a third shorter than hex for the same data. A SHA-256 digest is 32 bytes: 64 characters in hex and 44 in Base64, ending in a single = sign.
A worked example, bit by bit
The five bytes 48 65 6c 6c 6f spell Hello in ASCII. The first three bytes fill one group exactly. The last two bytes hold 16 bits, which need three characters with two zero bits added, and one = to complete the group of four.
48 65 6c -> 010010 000110 010101 101100 -> S G V s
6c 6f -> 011011 000110 111100 -> b G 8 =
48 65 6c 6c 6f -> SGVsbG8=
de ad be ef -> 3q2+7w==
ff d8 ff e0 -> /9j/4A==Accepted hex formats and the one error
The parser removes separators first and then requires an even number of hex digits. All of these inputs produce SGVsbG8=.
- Continuous digits: 48656c6c6f
- Space or line separated, as in a hex dump: 48 65 6c 6c 6f
- C-style array values: 0x48, 0x65, 0x6C, 0x6C, 0x6F
- Colon separated, as in certificate fingerprints: 48:65:6c:6c:6f
- Hyphen separated: 48-65-6c-6c-6f
- Uppercase, lowercase or mixed case digits
Why the converter rejects some input
Anything else stops with the message Enter one or more complete hexadecimal bytes. The usual causes are an odd number of digits, a character that is not a hex digit, backslash escapes such as \x48, surrounding brackets, or an empty box.
Digits are paired after the separators are gone, so single-digit bytes are not padded for you. Write 0a, not a. The input f 0a becomes f0a, which is three digits and fails.
Where developers convert hex to Base64
Command-line hash tools print digests in hex, while Subresource Integrity attributes, the Content-MD5 header and many API signature schemes want the digest in Base64. Keys and initialization vectors are often generated as hex and stored as Base64 in configuration. Converting also helps when you need to compare a hex dump from a debugger with a Base64 field in an API response.
Frequently asked questions
Why is my result different from a text to Base64 encoder?
A text encoder encodes the characters you typed. The text 48656c6c6f becomes NDg2NTZjNmM2Zg==, which is the Base64 of ten ASCII digits. This tool decodes the hex first, so the same input gives SGVsbG8=, the Base64 of five bytes.
Can I convert a SHA-256 hash from hex to Base64?
Yes. Paste the 64 hex digits and select Encode. The result is 44 characters long, including one = at the end, because 32 bytes leave a final group of two bytes.
Does it accept 0x prefixes, colons and commas?
Yes. Every 0x or 0X prefix is removed, along with whitespace, commas, colons and hyphens. Backslash-x escapes and brackets are not removed and cause an error, so strip those first.
Is the output standard Base64 or Base64URL?
It is standard Base64 with + and / and = padding. If you need the URL-safe form, for example for a JSON Web Key, pass the result through the Normalize Base64 tool and choose URL-safe, unpadded.
Is the hex I paste sent to a server?
No. Parsing and encoding happen in JavaScript on this page, which matters when the bytes are a key or a secret. Nothing in the box is transmitted.
How can I preserve leading zero bytes?
Enter both digits for every byte. For example, 00 ff encodes as AP8=, while ff alone encodes as /w==.