Base64 to Hex: How 4-Bit and 6-Bit Encoding Works

PublishedToolBase64 to Hex Converter

Contents
  1. What Hex and Base64 Really Are: 4-Bit vs. 6-Bit Encoding
  2. Convert Hex to Base64 by Hand: "48656c6c6f" (Hello)
  3. The Core Mechanism: 3 Bytes = 6 Hex Characters = 4 Base64 Characters
  4. Base64 vs. Hexadecimal (Hex / Base16): Full Comparison
  5. Five Common Base64–Hex Conversion Mistakes
  6. A Foolproof 5-Step Base64 ⟷ Hex Workflow
  7. 7 Tips for Converting Hex and Base64
  8. Final decision tree: which format should you use?
  9. Cheat sheet: base conversion and cryptography terms
  10. Frequently asked questions

You've probably been there: you're working with the same SHA-256 hash or encryption key, but one developer tool prints it as '48656c6c6f' (hexadecimal), while a cloud API returns 'SGVsbG8=' (Base64). They look like completely different pieces of data, and that can be confusing.

The two strings look nothing alike, but they're just the same binary byte array stored in computer memory, written in two different numbering systems.

This guide covers the math behind rearranging bits between hexadecimal (Hex, 4 bits) and Base64 (6 bits), the rule that Hex strings must have an even number of characters, and a technique for converting between the two formats in one second when verifying cryptographic signatures.

Key takeaways ① Same data, different notation: Hex writes 1 byte (8 bits) as two hexadecimal characters. Base64 writes 3 bytes (24 bits) as four base-64 characters. That's the only difference. ② The even-length rule for Hex: Two Hex characters always make 1 byte. If the string length is odd, the last byte is incomplete, and the conversion fails. ③ The size difference: Hex expands data to 2x its original size (200%). Base64 expands it only about 1.33x (+33%), which makes Base64 much better for network transfer. ④ With our converter, you can convert between Hex and Base64 in both directions in real time and normalize whitespace and letter case in one second.

What Hex and Base64 Really Are: 4-Bit vs. 6-Bit Encoding

A byte, the basic unit of computer memory, consists of 8 bits (each one a 0 or 1):

  • Hexadecimal (Hex / Base16): Splits 8 bits into two 4-bit groups and writes each group as one character (0–9, a–f), for 2 characters total. (1 byte = 2 characters)
  • Base64: Splits 24 bits (3 bytes) into four 6-bit groups and writes each group as one character (A–Z, a–z, 0–9, +, /), for 4 characters total. (3 bytes = 4 characters)

In other words, 6 Hex characters (3 bytes) hold exactly the same original data as 4 Base64 characters.

Convert Hex to Base64 by Hand: "48656c6c6f" (Hello)

Here are the five bit-operation steps for converting the hex string 48 65 6c 6c 6f (5 bytes) to Base64:

  1. Convert Hex to binary bytes:
    • 48 ➔ 01001000, 65 ➔ 01100101, 6c ➔ 01101100, 6c ➔ 01101100, 6f ➔ 01101111
  2. Join them into a 40-bit stream: 01001000 01100101 01101100 01101100 01101111
  3. Split into 6-bit groups (pad the last group with zeros):
    • [010010] [000110] [010101] [101100] [011011] [000110] [111100] (7 groups)
  4. Map each group to a Base64 character index:
    • 18(S), 6(G), 21(V), 44(s), 27(b), 6(G), 60(8) ➔ SGVsbG8
  5. Add padding equals signs (=): 5 bytes is 1 byte short of a multiple of 3, so add one '=' at the end to get the final result, SGVsbG8=.
Base64 to Hex Converter

Free · Lossless, real-time conversion between Base64 and hex in both directions, in one second, just by typing text


The Core Mechanism: 3 Bytes = 6 Hex Characters = 4 Base64 Characters

Here's how the two formats line up bit for bit from a computer architecture standpoint.

1. Byte alignment and the base conversion formula

N bytes ⇔ 2N Hex Characters ⇔ 4 × ⌈ N/3 ⌉ Base64 Characters
  • Example (SHA-256 hash = 32 bytes):
    • Hex: 32 × 2 = 64 characters (e.g., e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855)
    • Base64: 4 × ⌈ 32/3 ⌉ = 4 × 11 = 44 characters (e.g., 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=)

2. Why odd-length Hex strings cause errors

  • Each hexadecimal character carries exactly 4 bits (a nibble).
  • If the string length is odd (for example, 5 characters = 20 bits), the last 4 bits can't form a full 8-bit byte, so the string can't be converted to binary data at all.
  • The length must be even, or you need to pad the front with a '0' to make it even.

Base64 vs. Hexadecimal (Hex / Base16): Full Comparison

ComparisonHexadecimal (Hex / Base16)Base64 (RFC 4648)
Information per character4 bits (nibble)6 bits
Character set16 characters (0–9, a–f / A–F)64 characters (A–Z, a–z, 0–9, +, /)
Size to represent 1 byte2 charactersAbout 1.33 characters
Size increase vs. original+100% (2x expansion)+33.3% (1.33x)
Readability at byte boundariesBest (1 byte = 2 characters, an intuitive 1:1 mapping)Fair (3 bytes are grouped into 4 characters)
Padding characterNoneEquals sign (=, ==)
Common usesCryptographic hashes (SHA/MD5), memory dumps, MAC addressesWeb tokens (JWT), email attachments, image data URIs

Five Common Base64–Hex Conversion Mistakes

  1. Entering a Hex string with an odd number of characters: This breaks the two-characters-per-byte rule and throws a "length must be even" parsing error.
  2. Leaving the '0x' prefix or colons (:) in Hex: Special characters such as 0x or AA:BB:CC get mistaken for hex digits and produce the wrong value.
  3. Ignoring case in Base64: Hex is case-insensitive (0xAB == 0xab), but Base64 treats 'A' and 'a' as completely different values, so case must be preserved.
  4. Comparing hash strings directly: Two identical hashes can fail a direct == comparison if one is a Hex string and the other is Base64.
  5. Losing the '+' character in Base64 in URL environments: Before converting to Hex, people forget to check whether a '+' inside the Base64 was corrupted into a space.

A Foolproof 5-Step Base64 ⟷ Hex Workflow

  1. Step 1 (Prepare your input): Copy the hexadecimal Hex hash or Base64 string you need to convert.
  2. Step 2 (Paste it into the converter): Put the value in either the Base64 or the Hex input field.
  3. Step 3 (Convert automatically in real time): As soon as you type in one field, the other format updates in 0.001 seconds.
  4. Step 4 (Customize the formatting options): When outputting Hex, check 'Space between bytes' or 'Uppercase (A-F)' to make it easier to read.
  5. Step 5 (Copy the result and use it in your code): Copy the converted string and use it in an OpenSSL command, an API request, or your encryption code.

7 Tips for Converting Hex and Base64

  1. Convert in one second with an openssl command: echo -n "SGVsbG8=" | base64 -d | xxd -p (Base64 ➔ Hex)
  2. A one-line Node.js conversion: Buffer.from('48656c6c6f', 'hex').toString('base64') and the reverse, Buffer.from('SGVsbG8=', 'base64').toString('hex')
  3. The 64-character Hex ➔ 44-character Base64 formula for SHA-256: a 64-character Hex hash always becomes exactly 44 characters in Base64 (with a single '=' at the end).
  4. The 32-character Hex ➔ 24-character Base64 formula for MD5: a 32-character Hex MD5 always becomes exactly 24 characters in Base64 (with '==' at the end).
  5. Normalize case: standardize Hex to lowercase (toLowerCase()) before comparing, so comparisons don't break between systems.
  6. Save network bandwidth: when you send a large list of binary hashes through an API, Base64 cuts traffic by 33% compared to Hex.
  7. Bookmark this converter: when you're debugging API encryption keys or verifying blockchain transaction hashes, it clears the format barrier in a second.

Final decision tree: which format should you use?

  • Case A (you need to check byte offsets by eye or dump memory) ➔ Hexadecimal Hex (intuitive 1:1 mapping)
  • Case B (you're sending lots of hashes or binary over a network API) ➔ Base64 (33% less data)
  • Case C (OpenSSL CLI or Linux command-line tool parameters) ➔ Hex (-K, -iv options)
  • Case D (JSON payloads, HTTP headers, JWT tokens) ➔ Base64 / Base64URL

Cheat sheet: base conversion and cryptography terms

  • Hexadecimal: a base-16 notation that expresses the numbers 0 through 15 using 0–9 and A–F.
  • Nibble: a 4-bit unit, half of one byte (8 bits) — it maps exactly to one Hex character.
  • Digest: the fixed-length binary output produced by a hash function such as SHA-256.
  • Byte buffer: a contiguous array of raw 8-bit binary bytes stored sequentially in computer memory.

Frequently asked questions

Why do I get a "length must be even" error when I enter a Hex string?

In hexadecimal notation, two characters must always be combined to form one byte (8 bits) of data. With an odd number of characters, the last byte can't be completed, so the conversion isn't possible. Add a leading '0' to make the length even.

Does converting between Base64 and Hex corrupt or alter the original data?

Not at all. The only difference is whether the binary bits are grouped in 4-bit units or 6-bit units. It's a reversible conversion with no bit loss.

Is the encryption key or secret hash I enter sent to a server?

Never. All of this converter's Hex and Base64 bit operations run locally in the JavaScript engine inside your browser, so there's no risk of your security keys being exposed externally.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. bcrypt Hash Generator: 60-Character Structure ExplainedSee how a bcrypt hash is built: version, cost, 22-character salt, and 31-character digest — plus why the same password hashes differently every time.
  2. Brand Name Combiner: Turn Two Words Into Name CandidatesSee how two words turn into 14 brand name candidates with join, hyphen, syllable mix, and suffix rules, plus what the tool does not check.
  3. Business English Email Phrases: Formality Levels ComparedCompare business English email greetings, requests, apologies, and sign-offs by formality, with sentences for Dear vs Hi and Best regards vs Sincerely.
  4. camelCase vs snake_case: How the Conversion Rules WorkSee exactly where a converter splits text into words and how each format joins them again, including what happens with acronyms, numbers, and mixed scripts.
  5. Character Count With or Without Spaces: How to Match the LimitCharacter counts differ by tool. Why cover letters and reports count spaces, line breaks, and bytes differently, and how to check any counter yourself.
  6. Remove null and empty values from JSON: what stays and what goesClean null, empty strings, arrays, and objects out of JSON with one recursive rule. See why 0 and false survive and when invalid JSON is rejected.

Related tools