What is Hex to Base64 Converter?
This hex to Base64 converter translates the same bytes between two common text representations. Hexadecimal writes each byte as two characters (0–9 and A–F), which is easy to read and is how hashes, keys and binary dumps are usually shown; Base64 writes every 3 bytes as 4 characters, which is more compact and is what many APIs and formats expect.
Use Encode to turn hex such as 48656c6c6f into Base64 (SGVsbG8=), or Decode to turn Base64 into uppercase hex, optionally with a space between each byte for readability. The bytes themselves never change, only the way they are written.
How to use Hex to Base64 Converter
- Choose Encode for hex to Base64, or Decode for Base64 to hex.
- Paste your hex string (spaces are fine) or your Base64 string.
- For Base64 to hex, toggle Space Separators to show bytes as 48 65 6C or 48656C.
- Copy the result.
Key features
- Hex to Base64 and Base64 to hex
- Accepts hex with or without spaces
- Uppercase hex output
- Optional spaces between bytes
- Clear errors for odd-length or invalid hex
- Runs entirely in your browser
Common use cases
- Converting SHA-256 hashes between hex and Base64 for Subresource Integrity and digests
- Translating keys and IVs between formats for cryptography libraries
- Reading Base64 binary values as hex while debugging protocols
- Converting hex dumps from Wireshark or xxd into Base64
- Preparing binary test data for APIs
Technical details & standards
Hex input is cleaned of whitespace, then must contain an even number of characters from 0–9 and A–F; each pair becomes one byte, and the bytes are encoded as standard Base64 (RFC 4648). Base64 input is decoded to bytes and each byte is written as two uppercase hex digits.
Hex uses 2 characters per byte and Base64 about 1.33, so Base64 is roughly a third shorter. A common use is converting hash digests: tools like sha256sum print hex, while HTTP headers such as Content-Digest and Subresource Integrity attributes use Base64 of the same bytes.
How to convert hex to Base64 by hand
Hex and Base64 both describe bytes: hex uses 4 bits per character and Base64 uses 6. So the conversion goes through the bits. Here is 48656C, three bytes that make exactly four Base64 characters:
- Split the hex into byte pairs and write each as 8 bits: 48 = 01001000, 65 = 01100101, 6C = 01101100.
- Join the 24 bits and cut them into groups of six: 010010, 000110, 010101, 101100.
- Turn each group into a number: 18, 6, 21 and 44.
- Look each number up in the Base64 alphabet, where A–Z are 0–25, a–z are 26–51, 0–9 are 52–61, then + and /: 18 = S, 6 = G, 21 = V, 44 = s.
Result: 48656C in hex is SGVs in Base64. When the byte count is not a multiple of three, the last group is padded with zero bits and = signs, so 4865 becomes SGU=.
Hex to Base64 in Python, JavaScript and the terminal
Hex and Base64 are both ways of writing bytes, so convert the hex to raw bytes first and then encode them. Encoding the hex characters themselves gives a much longer, wrong result.
Python
import base64
base64.b64encode(bytes.fromhex("48656c6c6f")).decode() # 'SGVsbG8='
base64.b64decode("SGVsbG8=").hex() # '48656c6c6f'JavaScript (Node.js)
Buffer.from("48656c6c6f", "hex").toString("base64"); // "SGVsbG8="
Buffer.from("SGVsbG8=", "base64").toString("hex"); // "48656c6c6f"Terminal
echo 48656c6c6f | xxd -r -p | base64 # SGVsbG8=
echo SGVsbG8= | base64 -d | xxd -p # 48656c6c6fFrequently asked questions
How do I convert hex to Base64?
Paste the hex string in Encode mode. Each pair of hex digits becomes a byte, and the bytes are Base64-encoded. In code: base64.b64encode(bytes.fromhex(h)).decode() in Python, or Buffer.from(h, "hex").toString("base64") in Node.js. In a shell: echo 48656c6c6f | xxd -r -p | base64.
Why does it say my hex string is invalid?
Hex must have an even number of digits, two per byte, and only contain 0–9 and A–F. Remove prefixes such as 0x and any separators other than spaces.
How do I convert Base64 to hex?
Choose Decode and paste the Base64 string: SGVsbG8= becomes 48 65 6C 6C 6F with Space Separators on, or 48656C6C6F with it off. In code: base64.b64decode(s).hex() in Python, Buffer.from(s, "base64").toString("hex") in Node.js, or echo SGVsbG8= | base64 -d | xxd -p in a shell. The tool writes uppercase hex; those commands write lowercase.
Is hex or Base64 more compact?
Base64. Hex uses 2 characters per byte, Base64 about 1.33, so the same data is about a third shorter in Base64.
How do I convert a SHA-256 hash to Base64?
Paste the 64-character hex hash in Encode mode. The 44-character Base64 result is the format used by Subresource Integrity (sha256-…) and Content-Digest headers.