What is Hex Encoding?
Hexadecimal (hex) encoding converts binary or text data into a string of hexadecimal digits, representing each byte as exactly two characters from the set 0–9 and A–F. It is the most direct way to view the raw byte values of any data.
Note: Like Base64, hex encoding is not encryption — it is easily reversible and provides no security. It is used purely for representation.
How hex encoding works
| Character | ASCII (decimal) | Hex | Binary |
|---|---|---|---|
H | 72 | 48 | 01001000 |
e | 101 | 65 | 01100101 |
x | 120 | 78 | 01111000 |
So "Hex" in hex encoding is 48 65 78. Each byte always becomes exactly 2 hex characters, making the output predictable and easy to parse.
Key properties
| Property | Description |
|---|---|
| Deterministic | Same input always produces the same hex output |
| Fixed size | Every byte becomes exactly 2 hex digits — output is always 2× input size |
| Reversible | Can be decoded back to the original data losslessly |
| Character set | Only 0–9 and A–F — safe in any text-based system |
Common use cases
- Cryptography — keys, IVs, hashes and signatures are commonly displayed as hex strings
- Debugging — hex dumps let developers inspect raw bytes in network packets and files
- Protocols — many low-level protocols (TLS, SSH, binary formats) use hex notation
- Colour codes — web colours like
#FF5733are hex-encoded RGB values - MAC / IP addresses — network addresses are shown as hex bytes
Hex vs Base64
| Property | Hex | Base64 |
|---|---|---|
| Size overhead | 2× (100% larger) | ~1.33× (33% larger) |
| Readability | Easy to inspect individual bytes | Compact but opaque |
| Character set | 0–9, A–F (16 chars) | A–Z, a–z, 0–9, +, / (64 chars) |
| Best for | Debugging, byte inspection | Transport efficiency, JWT, email |
