Hex Encoder & Decoder: Complete Guide
Learn how hex encoding works, when to use it, and how it compares to Base64. Includes examples, common mistakes, and real-world uses.
Quick Answer
Hex encoding converts each byte of data into a two-character string using digits 0-9 and
letters A-F. The word "Hello" becomes 48 65 6c 6c 6f. Each character maps
to its byte value in the ASCII or UTF-8 table, then that value is written in base 16.
This hexadecimal encoder handles both directions. Use it for text to hexadecimal conversion, or switch mode to run hex to text decoding. Paste and the result appears instantly.
Try the Hex Encoder & Decoder →What Is Hex Encoding?
Computers store all data as bytes: numbers between 0 and 255. Reading raw bytes is impractical because most values fall outside the range of printable characters. A hexadecimal encoder solves this by converting every byte into exactly two readable characters from the hexadecimal alphabet (0-9, A-F).
"Hexadecimal" means base 16. Where the familiar decimal system counts in groups of 10 (0-9), hexadecimal counts in groups of 16 (0-9, then A for 10, B for 11, up to F for 15). Two hex digits cover all 256 possible byte values, from 00 to FF.
The result is a hex string: a sequence of character pairs, one pair per byte. You will see it in network packet dumps, color codes (#FF5733), cryptographic hashes (SHA-256 outputs), and memory debuggers. It is not compressed or encrypted. It is a display format that makes byte values visible.
Hex vs binary representation: binary writes each byte as eight 0s and 1s (byte 65 is
01000001). Hex writes the same byte as two characters (41).
Both carry identical information, but hex is four times shorter and far easier to read.
A hex string converter is the standard tool for human-readable byte inspection; raw
binary output is left to low-level debuggers.
How Are Bytes Represented in Hex?
Each byte is a number from 0 to 255. Two hex digits cover that full range exactly: "00" is 0, "FF" is 255. The hex text conversion takes each character, finds its byte value in the UTF-8 table, then writes that value as two hex digits.
Here is a concrete example. The letter "A" has ASCII value 65. In base 16, 65 equals
4 times 16 plus 1, so the hex code is 41. "B" is 66, which gives 42.
The word "Hi" encodes as 48 69. Spaces between pairs are a readability
convention, not part of the hex string itself.
Decoding reverses the process. Each pair of hex digits is read as a base-16 number,
converted to a byte value, and the byte sequence is interpreted as UTF-8 text. The hex
to text conversion of 48 gives decimal 72, which is the letter "H". The
result is byte-for-byte identical to the original input.
ASCII characters produce one byte (two hex digits) each. Characters outside ASCII, such as accented letters or emoji, use two to four bytes and produce four to eight hex digits.
Hello 48 65 6c 6c 6f Hello
When Would You Use Hex Encoding?
Hex appears in several common development situations:
- Debugging binary data. When a program reads a file or network packet, the raw bytes contain control characters that are invisible in plain text. A hex dump shows every byte explicitly, making it possible to spot missing bytes, unexpected nulls, or encoding errors.
- Color codes. CSS colors like
#3a7bd5use hex encoding. The six characters represent three bytes: red (3a = 58), green (7b = 123), blue (d5 = 213). Knowing the hex format lets you decode any color code by hand. - Cryptographic output. SHA-256, MD5, and most other hash functions produce raw bytes. Those bytes are almost always displayed as a hex string. The 64-character SHA-256 output is 32 bytes written in hex.
- Escape sequences. URLs use percent-encoding, which is hex under a
different name. The space character (byte 32, hex 20) appears as
%20in a URL. Understanding hex makes it straightforward to read and write these sequences. - Protocol inspection. Network protocols, binary file formats, and database storage expose bytes as hex in logs and debugging tools. A hex encoder lets you check what bytes your text actually produces before sending it.
Hex vs Base64: Which Should You Use?
Both hex and Base64 convert binary data to printable text, but they serve different purposes.
Hex output is always exactly twice the byte length of the input. "Hello" is 5 bytes, so its hex form is 10 characters. Each byte maps to a visible, human-readable pair. This makes hex ideal for debugging, logging, and any situation where you want to inspect individual bytes.
Base64 output is roughly 33% larger than the input, not 100% larger. It uses a 64-character alphabet instead of 16, so each character carries more information. Base64 is the standard choice when you need to embed binary data inside JSON, email, or HTML because the size overhead is smaller and the output contains only URL-safe characters.
Common Mistakes
Related Tools
You May Also Need
You may also need
- Base64 Encoder & DecoderAlternative binary-to-text encoding
- MD5 Hash GeneratorHash output is commonly displayed in hex
- SHA-256 Hash GeneratorHash output is commonly displayed in hex
Next steps
- Base64 Encoder & DecoderEncode data more compactly for embedding in JSON or HTML
- MD5 Hash GeneratorGenerate a hash and inspect the hex output
Alternatives
- Base64 Encoder & DecoderMore compact binary-to-text encoding for data transfer
- URL Encoder & DecoderPercent-encoding for URLs uses hex pairs