Lossless Conversion

Hex ↔ Base64 Online Converter

Convert Hexadecimal (base-16) byte strings to Base64 (base-64) format and vice versa. 100% client-side with real-time feedback.

Hex String Input0 chars
Base64 Output0 chars
SGVsbG8gV29ybGQ=

Hexadecimal vs Base64 Conversion: Technical Comparison

Hexadecimal (Base16) and Base64 are the two most widely used text encodings for representing raw binary byte sequences in programming and cryptography.

Format Comparison: Hex vs Base64

PropertyHexadecimal (Hex / Base16)Base64
Alphabet Set16 chars (0-9, A-F)64 chars (A-Z, a-z, 0-9, +, /)
Bits per Char4 bits (1 nibble)6 bits
Size Overhead100% expansion (2x raw byte length)33.3% expansion (1.33x raw byte length)
Best ForSHA-256 hashes, MAC addresses, memory dumpsData URIs, JWT tokens, API payloads, file transfer

Code Snippet: Convert Hex to Base64 in JavaScript

// Convert Hex string to Base64 in Node.js / Modern JS

const hexString = "48656c6c6f20576f726c64";

const base64String = Buffer.from(hexString, 'hex').toString('base64');

// Result: "SGVsbG8gV29ybGQ="

Frequently Asked Questions (FAQ)

How does Hex to Base64 conversion work?

Hex to Base64 conversion translates hexadecimal byte representations (0-9, A-F) into raw binary bytes and then encodes those bytes into 6-bit Base64 ASCII characters. Base64 is significantly more compact than Hex strings.

Why is my Hex string invalid?

A Hex string is invalid if it contains characters outside the 0-9 and A-F range, or if it has an odd number of characters. Hex representation requires two characters per byte.

What is the size difference between Hex and Base64?

Hex encoding expands binary data by 100% (2 hex characters per byte, 16 bits for 8 bits data). Base64 encoding expands binary data by only ~33.3% (4 characters for 3 bytes), making Base64 much more efficient for data transmission.

When should I convert Hex to Base64?

Convert Hex to Base64 when you need to send cryptographic hashes, keys, or binary data through APIs, JSON payloads, or database fields while minimizing bandwidth and payload size.

Related Tools