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.
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
| Property | Hexadecimal (Hex / Base16) | Base64 |
|---|---|---|
| Alphabet Set | 16 chars (0-9, A-F) | 64 chars (A-Z, a-z, 0-9, +, /) |
| Bits per Char | 4 bits (1 nibble) | 6 bits |
| Size Overhead | 100% expansion (2x raw byte length) | 33.3% expansion (1.33x raw byte length) |
| Best For | SHA-256 hashes, MAC addresses, memory dumps | Data 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.
