Upload a file
  1. base64hub
  2. Other bases
  3. Hex to Base64

Hex to Base64 Converter for Hashes and Keys

Paste hex bytes and get the same bytes in Base64. A 64-digit SHA-256 digest becomes 44 Base64 characters, because the hex is decoded to bytes first instead of being encoded as text.

Free no sign-up, no limits Local nothing uploaded 44 chars for a SHA-256 digest, not 88 Updated Oct 27, 2026
Input 0Bytes 0 BOutput 0

Processed in your browser. This page cannot send your data anywhere – how we know

How to convert hex to Base64

  1. Paste the hex into Input · Hex. Spaces, line breaks, colons, dashes and 0x or \x prefixes are skipped, and case does not matter.
  2. The Base64 appears in Output · Base64 as you type.
  3. Under the output, untick Padding (=) if the receiver wants unpadded Base64, and set Line wrap to 64 (PEM) or 76 (MIME) for wrapped output.
  4. Copy output, or use the Base64 → Hex toggle to check the result in the other direction. Base64 to Hex is the same tool the other way round.

Hash digests: hex vs Base64

Hash functions return raw bytes. Command-line tools such as sha256sum and md5sum print those bytes as hex, while many protocols expect the same digest in Base64. These are the digests of the five bytes hello:

HashHex (from sha256sum etc.)Base64
MD55d41402abc4b2a76b9719d911017c592XUFAKrxLKna5cZ2REBfFkg==
SHA-1aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dqvTGHdzF6KLavt4PO0gs2a6pQ00=
SHA-2562cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=

Places that want the Base64 form:

  • Subresource Integrity. integrity="sha384-…" on a <script> or <link> tag holds a Base64 digest. The SRI hash generator builds the whole attribute from a file.
  • Content-MD5 headers. RFC 1864 defines the value as the Base64 of the 16-byte MD5 digest, and object stores that check uploads with it reject the hex form. See MD5 in Base64.
  • Signatures and HMACs in API requests, which are usually sent as Base64. HMAC in Base64 computes them in either form.
  • Keys and secrets: a 32-byte key printed by openssl rand -hex 32 becomes the 44-character Base64 value many config files expect.

For SHA-256 of your own text or file, SHA-256 in Base64 skips the hex step entirely.

The usual mistake: encoding the hex text

echo -n 2cf24d…9824 | base64 gives a plausible but wrong result. It encodes the 64 ASCII characters of the hex instead of the 32 bytes they stand for, and returns 88 characters starting with MmNmMjRk. That value decodes back to the hex text, so nothing complains until a signature or integrity check fails. Decode the hex first:

echo -n 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 | xxd -r -p | base64
# LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=

printf hello | openssl dgst -sha256 -binary | base64
# same result, without going through hex at all

xxd -r -p turns plain hex back into bytes. It ships with Vim; on minimal systems install the xxd package. With OpenSSL, -binary is what makes the digest come out as bytes instead of hex.

Hex to Base64 in code

import base64
base64.b64encode(bytes.fromhex("5d41402abc4b2a76b9719d911017c592")).decode()
# 'XUFAKrxLKna5cZ2REBfFkg=='
Buffer.from("5d41402abc4b2a76b9719d911017c592", "hex").toString("base64");
// 'XUFAKrxLKna5cZ2REBfFkg=='

The Python and Node.js pages cover the URL-safe and unpadded variants. When the digest goes into a URL or a JWT, convert the result with Base64 to Base64URL.

If the conversion fails

  • “odd number of hex digits”. Each byte needs two digits; one was lost when copying. Check both ends of the input.
  • “unexpected character”. Something that is not hex is in the input, such as a sha256: label or the file name that sha256sum prints after the digest. Remove it; Show jumps to the spot.
  • Offsets from a hex dump. In 00000010: 4865 6c6c the 00000010 is a position, not data, but it is valid hex and will be converted. Use xxd -p output, which has no offsets.

FAQ

How do I convert a SHA-256 hex hash to Base64?

Paste the 64 hex digits into the input. The result is 44 characters ending in =, for example 2cf24dba…9824 becomes LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=. On the command line: echo -n HEX | xxd -r -p | base64.

Why is my Base64 twice as long as it should be?

The hex string was encoded as text, so each hex digit became a byte. A SHA-256 digest done that way gives 88 characters instead of 44. Decode the hex to bytes first, which is what this converter does.

How many Base64 characters does a hex string give?

Two hex digits make one byte, and every 3 bytes become 4 Base64 characters, rounded up to a multiple of 4. 32 hex digits (MD5) give 24 characters, 40 (SHA-1) give 28, 64 (SHA-256) give 44 and 128 (SHA-512) give 88.

Can I convert a UUID to Base64?

Yes, paste it with the dashes. The 16 bytes of 123e4567-e89b-12d3-a456-426614174000 become Ej5FZ+ibEtOkVkJmFBdAAA==, 24 characters instead of 36.