FormatterHQ

Hex to Base64

Convert hexadecimal bytes — hash digests, keys, binary dumps — into Base64 or Base64URL. Spaces, colons, 0x and \x prefixes are all accepted.

Loading tool…
Ready.

How to use the Hex to Base64

  1. Type or paste into the Hex box, or click Sample. You can also drop a text file on either box, or load one into the Base64 box with its Open file button.
  2. The Base64 box updates live as you type. It works both ways — edit the Base64 side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Alphabet in the options bar above the editors; the result refreshes immediately. Hex case and Separator only affect the reverse direction, when you type in the Base64 box.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

Hex to Base64 for digests and binary data

Hex and Base64 are two text representations of the same bytes. Hex uses two characters per byte; Base64 uses about 1.33, so it is shorter. The hex to Base64 converter parses the hex into raw bytes and re-encodes them — it does not encode the hex characters themselves, which is the mistake that produces wrong results in many ad-hoc scripts.

Example

Input:

48 65 6c 6c 6f 20 f0 9f 91 8b

Output:

SGVsbG8g8J+Riw==

The ten bytes spell “Hello 👋” in UTF-8. Encoding the hex text itself would instead produce a much longer, meaningless string.

Why convert hash digests?

Many tools print hashes in hex, but several standards want Base64 of the raw digest bytes:

  • Subresource Integrity (SRI). The integrity attribute on <script> and <link> tags is sha384- followed by Base64 of the SHA-384 digest. Generate the hex digest with the SHA-384 Hash Generator, then convert it here.
  • HTTP checksum headers. Content-MD5 and several cloud storage checksum headers carry Base64 digests.
  • Keys and certificates often appear in hex in one tool and are needed in Base64 by another (for example in JSON Web Keys, which use Base64URL).

Accepted hex formats

Separators (spaces, commas, colons, semicolons, hyphens), 0x and \x prefixes and mixed case are removed before parsing, so plain hex from xxd -p, OpenSSL (AB:CD:EF), the values of a C array (without the braces) or hash tools can be pasted directly. A default xxd dump also has offset and text columns, which must be removed first. An odd number of digits gets a leading zero; any non-hex character is reported as an error.

The length of the hex input tells you what you have: two hex characters per byte, so 32 characters is 16 bytes (MD5), 64 characters is 32 bytes (SHA-256) and so on.

Digest lengths at a glance

AlgorithmHex lengthBase64 length
MD53224 (ends in ==)
SHA-14028 (ends in =)
SHA-2566444 (ends in =)
SHA-3849664 (no padding)
SHA-51212888 (ends in ==)

Doing it on the command line

echo -n "48656c6c6f" | xxd -r -p | base64 converts hex to Base64 in a shell, and in Python base64.b64encode(bytes.fromhex(h)) does the same. Choose URL-safe output for JWKs, JWT signatures and other Base64URL contexts.

Convert back with Base64 to Hex. Everything runs locally in your browser.

Frequently asked questions

How do I create an SRI hash from a hex digest?
Compute the SHA-384 digest of the file in hex, convert it to Base64 here, and prefix the result with sha384- in the integrity attribute.
Why is my result different from encoding the hex string as text?
This tool converts the bytes that the hex represents. Encoding the hex characters themselves produces a different, longer Base64 string that is usually not what an API expects.
Can I paste hex with colons, like OpenSSL output?
Yes. Colons, spaces, commas, hyphens and 0x or \x prefixes are removed automatically.
How much shorter is Base64 than hex?
Hex needs 2 characters per byte and Base64 about 1.33, so Base64 is roughly a third shorter. A SHA-256 digest is 64 hex characters but 44 Base64 characters.

Last updated October 3, 2026

Guides

Related tools