Convert Hex to Base64

Paste hex in almost any format — spaces, newlines or 0x prefixes are cleaned automatically — and get the Base64 instantly, in your browser.

Input — Hex○ Waiting for input

Nothing to convert yet

Nothing to convert yet — paste your data or drop a file to begin.

Your files and data stay in your browser.

Inspection Report

Result metadata
Detected Type
MIME Type
Encoding
Input Length
Decoded Size
Padding Status
Data URI
File Signature
Preview Availability

How to convert Hex to Base64

To convert hex to Base64, paste the hexadecimal string into the tool above. It accepts compact hex, space- or newline-separated bytes, and 0x-prefixed values, cleans the input automatically, and shows the exact byte count plus the Base64 result. Everything is converted locally in your browser — nothing is sent anywhere.

How to Use

  1. Paste your hex into the input box. 89504e47, 89 50 4e 47 and 0x89 0x50 0x4e 0x47 are all understood.
  2. Spaces, newlines and 0x prefixes are removed automatically; anything else invalid is flagged with its exact position.
  3. Check the byte count — each pair of hex digits is one byte.
  4. Copy the Base64 result, or the normalized hex if you need a clean version of your input.
  5. To decode Base64 back to hex, use the Base64 to Hex tool.

Real Example

Paste 48 65 6c 6c 6f and the tool reports 5 bytes and produces SGVsbG8= — the Base64 for the ASCII text "Hello". Paste the eight bytes 89 50 4e 47 0d 0a 1a 0a (with or without the spaces) and you get iVBORw0KGgo=, the famous opening of every Base64-encoded PNG. The normalized hex output shows your cleaned input, so you can verify exactly what was converted.

Code Snippets

// Hex (any spacing / 0x prefixes) to Base64 (browser) const clean = hex.replace(/0x/gi, '').replace(/[^0-9a-f]/gi, ''); const bytes = new Uint8Array(clean.match(/../g).map(h => parseInt(h, 16))); let binary = ''; bytes.forEach(b => (binary += String.fromCharCode(b))); const base64 = btoa(binary);

How Hex to Base64 Works

Hex shows up in the wild in many shapes: hex editors space-separate bytes, C code prefixes them with 0x, dumps add newlines every 16 bytes. This tool strips all of that before conversion and tells you exactly what it removed. What remains must be an even number of hex digits — two per byte — and the byte count display lets you sanity-check the length before trusting the output. The conversion itself is a direct byte re-encoding, so the Base64 always represents precisely the bytes your hex described.

Common Use Cases

  • Turning a hex dump from a debugger or protocol analyzer into Base64 for transport.
  • Preparing binary keys or hashes for systems that expect Base64 input.
  • Converting byte sequences from documentation into a format APIs accept.
  • Cleaning up inconsistently formatted hex before using it in code.

FAQ

Which hex formats can I paste?
Compact hex (89504e47), space- or newline-separated bytes (89 50 4e 47), and 0x-prefixed bytes (0x89 0x50) all work. The separators and prefixes are removed automatically.
What happens if my hex has an odd number of digits?
The conversion stops with a clear error, because each byte needs exactly two hex digits. Check for a missing or extra character — the message tells you the cleaned length.
How do I convert the Base64 result back to hex?
Use the Base64 to Hex tool — it decodes any Base64 back to hex with the same byte-count display.
Why does my hex fail validation?
Something other than 0–9, a–f, spaces, newlines or 0x prefixes is in the input. The error names the first invalid character and its position so you can fix it directly.

Related Tools