Hexadecimal Hash Digest Format

Understand hexadecimal encoding of hash digests: how binary hash output is converted to hex strings, formatting conventions, and how to work with hex digests in code.

General

Detailed Explanation

When a hash function produces its output, the result is a sequence of raw bytes. Hexadecimal encoding converts each byte into two characters (0-9, a-f), creating a human-readable string representation. This hex digest format is the most common way to display and transmit hash values.

How hex encoding works:

Each byte (8 bits, values 0-255) is represented by exactly two hexadecimal digits. The byte value 0 becomes "00", the byte value 255 becomes "ff", and the byte value 171 becomes "ab". This encoding is lossless and bidirectional: you can always convert between raw bytes and their hex representation. SHA-256 produces 32 bytes, which become 64 hex characters. MD5 produces 16 bytes, which become 32 hex characters.

Case conventions:

Hex digests can use lowercase (a-f) or uppercase (A-F). Most Unix tools (sha256sum, md5sum) output lowercase. Some Windows tools and older standards use uppercase. Technically, "4a3b2c" and "4A3B2C" represent the same value. When comparing hashes, always normalize to the same case first, or use case-insensitive comparison. Most programming languages' hex encoding functions default to lowercase.

Working with hex digests in code:

In JavaScript: Array.from(new Uint8Array(buffer)).map(b => b.toString(16).padStart(2, '0')).join(''). In Python: hashlib.sha256(data).hexdigest(). In Go: fmt.Sprintf("%x", hash.Sum(nil)). In Java: String.format("%064x", new BigInteger(1, digest)). Note the padStart(2, '0') in JavaScript, which ensures bytes like 0x0A are rendered as "0a" not "a", preserving the fixed-length property.

Formatting variations:

Some tools insert separators for readability: "4a:3b:2c:1d" (colon-separated, common in certificate fingerprints), "4A 3B 2C 1D" (space-separated, common in hex editors), "4a3b2c1d" (no separator, standard for checksums). Certificate fingerprints in browsers are typically displayed colon-separated and uppercase: "AB:CD:EF:12:34:56...".

Hex vs other encodings:

Hex encoding uses 2 characters per byte (100% expansion). Base64 uses 4 characters per 3 bytes (33% expansion). Base32 uses 8 characters per 5 bytes (60% expansion). Raw binary uses 1 byte per byte (no expansion). Hex is preferred for hash digests because it is easy to read, compare visually, copy-paste, and debug, despite being the least compact text encoding.

Use Case

Understanding hex digest format is essential for developers working with hash verification, certificate fingerprints, and any system that displays or transmits hash values.

Try It — Hash Generator

Open full tool