Base64 to Hex

Convert between Base64 and hexadecimal

Base64

Hex

Runs locally · Safe to paste secrets
Output will appear here…
Base64 → Hex

What Is Base64 to Hex Conversion?

Base64 to hex conversion transforms data between two common binary-to-text encoding schemes. Base64 represents binary data using 64 ASCII characters (A-Z, a-z, 0-9, +, /), encoding every 3 bytes as 4 characters. Hexadecimal represents each byte as exactly two characters from a 16-symbol alphabet (0-9, a-f). Converting between these formats is a two-step process: decode the Base64 string into its raw bytes, then re-encode those bytes in the target format.

Hexadecimal notation is the standard representation for binary data in low-level programming, cryptography, and network protocols. Each hex character maps directly to a 4-bit nibble, making it straightforward to read individual byte values. A SHA-256 hash, for example, is almost always displayed as a 64-character hex string. Base64, by contrast, is optimized for compactness — the same hash takes only 44 characters in Base64 — and is the standard encoding for email attachments (MIME), data URIs, and API payloads.

Both encodings are defined in RFC 4648. The conversion between them is lossless: no data is added or removed, only the textual representation changes. This makes Base64-to-hex conversion a routine operation when debugging encrypted payloads, inspecting certificate fingerprints, or verifying hash outputs across systems that use different display formats.

Why Use This Base64 to Hex Converter?

This tool converts between Base64 and hexadecimal directly in your browser. No data leaves your machine, and the conversion happens in real time as you type.

Instant Conversion
Paste Base64 or hex and see the result immediately — no round-trip to a server. Bidirectional mode lets you flip between directions with one click.
🔒
Privacy-First Processing
All conversion runs locally in your browser using JavaScript. Your cryptographic keys, hashes, and tokens are never transmitted over the network.
Bidirectional Mode
Switch between Base64-to-hex and hex-to-Base64 with a single button. The tool detects and handles both standard and URL-safe Base64 variants.
📋
Clean Output, Ready to Paste
Output is lowercase hex without delimiters or prefixes — the format expected by most APIs, CLIs, and programming languages. Copy it with one click.

Base64 to Hex Use Cases

Frontend Developer
Convert Base64-encoded API responses to hex when debugging binary protocols, WebSocket frames, or ArrayBuffer contents in the browser DevTools console.
Backend Engineer
Translate Base64 hash digests from JWT signatures or HMAC responses into hex to compare against OpenSSL or database-stored values that use hex representation.
DevOps / SRE
Verify TLS certificate fingerprints by converting the Base64 public key from PEM files into the hex fingerprint format displayed by browsers and monitoring tools.
Security Analyst
Inspect encryption keys and initialization vectors (IVs) that arrive as Base64 in API traffic — convert to hex for byte-level analysis in Wireshark or CyberChef.
Data Engineer
Transform Base64-encoded binary columns from databases (PostgreSQL bytea, MongoDB BinData) into hex for comparison, logging, or migration scripts.
Student / Learner
Understand the relationship between Base64 and hexadecimal by seeing how the same bytes are represented in each format, reinforcing encoding fundamentals.

Base64 vs Hexadecimal Encoding

Base64 and hexadecimal both convert binary data to printable text, but they make different trade-offs between compactness and readability. The table below summarizes the key differences.

PropertyBase64Hexadecimal
AlphabetA-Z a-z 0-9 + / =0-9 a-f
Bits per character64
Size overhead~33% larger than raw100% larger than raw
ReadabilityCompact but opaqueEach byte visible as 2 chars
Primary useEmail, data URIs, APIsCrypto hashes, MAC addresses, colors
SpecificationRFC 4648IEEE 754, RFC 4648 sec 8

Conversion Examples

The table below shows identical byte sequences in their Base64 and hexadecimal representations. Notice that hex output is always exactly twice the byte count, while Base64 length equals ceil(byteCount / 3) * 4.

Input (text / bytes)Base64Hex
HelloSGVsbG8=48656c6c6f
ABQUI=4142
0xFFMHhGRg==30784646
AAE=0001
key=vala2V5PXZhbA==6b65793d76616c
Þ­¾ï (bytes)3q2+7w==deadbeef

How the Conversion Works

Converting Base64 to hexadecimal is a two-phase process. First, the Base64 string is decoded into raw bytes by mapping each character to its 6-bit value, concatenating the bits, and splitting them into 8-bit bytes (discarding padding). This step reverses the encoding defined in RFC 4648 Section 4.

Second, each byte is converted to its two-digit hexadecimal representation. The byte value 0-255 maps to 00-ff. A byte like 0x4F (decimal 79) becomes the two characters '4' and 'f'. The complete hex string is simply the concatenation of all two-character pairs. The reverse direction (hex to Base64) applies these steps in reverse order: parse hex pairs into bytes, then Base64-encode the result.

4-bit binaryHex digit
00000
00011
00102
00113
01004
01015
01106
01117
10008
10019
1010a
1011b
1100c
1101d
1110e
1111f

Code Examples

These runnable snippets show how to convert between Base64 and hex in JavaScript, Python, Go, and the command line. Each example covers both conversion directions.

JavaScript (browser / Node.js)
// Base64 to Hex
function base64ToHex(b64) {
  const raw = atob(b64)
  return Array.from(raw, c =>
    c.charCodeAt(0).toString(16).padStart(2, '0')
  ).join('')
}
base64ToHex('SGVsbG8=') // → "48656c6c6f"

// Hex to Base64
function hexToBase64(hex) {
  const bytes = hex.match(/.{1,2}/g).map(b => parseInt(b, 16))
  return btoa(String.fromCharCode(...bytes))
}
hexToBase64('48656c6c6f') // → "SGVsbG8="

// Node.js Buffer shorthand
Buffer.from('SGVsbG8=', 'base64').toString('hex')   // → "48656c6c6f"
Buffer.from('48656c6c6f', 'hex').toString('base64')  // → "SGVsbG8="
Python
import base64, binascii

# Base64 to Hex
b64_str = 'SGVsbG8='
raw_bytes = base64.b64decode(b64_str)
hex_str = raw_bytes.hex()            # → '48656c6c6f'
# or: binascii.hexlify(raw_bytes).decode()

# Hex to Base64
hex_str = '48656c6c6f'
raw_bytes = bytes.fromhex(hex_str)
b64_str = base64.b64encode(raw_bytes).decode()  # → 'SGVsbG8='

# One-liner for quick conversion
base64.b64encode(bytes.fromhex('deadbeef')).decode()  # → '3q2+7w=='
Go
package main

import (
    "encoding/base64"
    "encoding/hex"
    "fmt"
)

func main() {
    // Base64 to Hex
    raw, _ := base64.StdEncoding.DecodeString("SGVsbG8=")
    hexStr := hex.EncodeToString(raw)
    fmt.Println(hexStr) // → "48656c6c6f"

    // Hex to Base64
    raw2, _ := hex.DecodeString("48656c6c6f")
    b64Str := base64.StdEncoding.EncodeToString(raw2)
    fmt.Println(b64Str) // → "SGVsbG8="
}
CLI (bash)
# Base64 to Hex (using base64 + xxd)
echo -n 'SGVsbG8=' | base64 -d | xxd -p
# → 48656c6c6f

# Hex to Base64
echo -n '48656c6c6f' | xxd -r -p | base64
# → SGVsbG8=

# OpenSSL alternative
echo -n 'SGVsbG8=' | openssl base64 -d | xxd -p
# → 48656c6c6f

Frequently Asked Questions

What is the difference between Base64 and hexadecimal?
Base64 uses 64 characters and encodes 6 bits per character, resulting in about 33% size overhead compared to raw bytes. Hexadecimal uses 16 characters and encodes 4 bits per character, resulting in 100% overhead — exactly double the original size. Base64 is more compact; hex is more human-readable because each byte maps to exactly two characters.
Is Base64-to-hex conversion lossy?
No. Both Base64 and hex are deterministic, reversible encodings of the same underlying bytes. Converting between them does not alter, compress, or encrypt the data. The raw byte sequence is identical before and after conversion — only the textual representation changes.
Why is my hex output longer than the Base64 input?
Hex always produces 2 characters per byte, while Base64 produces about 1.33 characters per byte. A 20-byte value is 28 Base64 characters but 40 hex characters. This is the inherent trade-off: hex is larger but each byte boundary is immediately visible.
Can I convert Base64url (URL-safe Base64) to hex?
Yes. Base64url replaces + with - and / with _ and omits padding. This tool automatically normalizes Base64url input before conversion. In code, replace - with + and _ with / then add padding before decoding: the resulting bytes are identical to standard Base64.
How do I convert a SHA-256 hash from Base64 to hex?
Paste the Base64 hash into this tool to get the 64-character hex string. In code: decode the Base64 string into bytes (32 bytes for SHA-256), then hex-encode those bytes. For example, in Python: bytes.fromhex is the reverse — base64.b64decode(b64_hash).hex() gives you the hex representation.
What happens if the Base64 input contains whitespace or newlines?
Most Base64 decoders, including this tool, strip whitespace before decoding. PEM-encoded certificates and MIME-encoded content typically wrap Base64 at 64 or 76 characters per line. The line breaks are not part of the encoded data and are safely ignored during conversion.
When should I use hex instead of Base64?
Use hex when you need byte-level readability — inspecting cryptographic output, debugging binary protocols, or specifying color values (#ff5733). Use Base64 when compactness matters — embedding data in JSON, transmitting over email (MIME), or constructing data URIs. For storage and transmission, Base64 saves about 33% space compared to hex.