Hexadecimal—or "hex" for short—is everywhere in programming. From web colors to memory addresses, MAC addresses to Unicode characters, understanding hex is essential for any developer. This guide starts from the very basics—what a hex code is and how to read one—then builds up to the everyday places you'll meet hex.
What Is Hexadecimal and Why It Exists
Hexadecimal is simply a way of writing numbers using base 16 instead of the base 10 you count with every day. In everyday decimal, each place value is a power of 10 (ones, tens, hundreds). In hexadecimal, each place value is a power of 16 (ones, sixteens, two-hundred-fifty-sixes). That's the whole idea—"hexadecimal code" is just numbers written in this base-16 shorthand.
So why does hex exist at all? Computers don't actually think in decimal or hex—they think in binary, using only 0 and 1 (see Binary Numbers Explained for the full story). Binary is precise but painfully long to read: a single byte like 11111111 is eight characters of ones and zeros.
Here's the trick that makes hex so useful: one hex digit represents exactly 4 binary bits (a "nibble"). Four bits can hold 16 possible values (0000 through 1111), and hex has exactly 16 digits to match them one-for-one. That means any group of 4 bits collapses into a single, tidy hex digit:
Binary: 1111 1111 (8 bits, hard to scan)
Hex: F F (2 digits, easy to read)
Hex is popular because it's a compact shorthand for binary. It's far shorter and less error-prone to read than binary, yet—unlike decimal—it lines up perfectly with how bits are grouped inside the machine. That balance is exactly why you see hex used for colors, memory addresses, byte values, and more.
How to Read a Hex Value
When you meet a hex value in the wild, it usually carries a marker so you know it's base 16, not decimal:
0xprefix — common in code:0x1F,0x41,0xFF. The0xisn't part of the number; it just means "the following is hexadecimal."#prefix — used for web colors:#FF5733.%prefix — used in URL encoding:%20.- A trailing
hor subscript 16 — seen in some assembly and textbooks:1Fhor1F₁₆.
To actually read a hex number, work through the digits the same way you read decimal—left is the "big" end, right is the "small" end. Take a two-digit byte like 0x3A:
0x3A
││
│└─ low nibble (the right digit) = A = 10
└── high nibble (the left digit) = 3
Value = (3 × 16) + (10 × 1) = 48 + 10 = 58
Each hex digit is called a nibble. In a byte (two hex digits), the left digit is the high nibble and the right digit is the low nibble. The high nibble counts sixteens; the low nibble counts ones. Reading two digits at a time is the natural way to scan hex, because two hex digits always equal exactly one byte.
Hex ↔ Decimal ↔ Binary Quick Reference
This table is the one to bookmark. The top block covers every single hex digit (0–15); the bottom block adds common byte values you'll run into constantly.
| Decimal | Hex | 4-bit Binary | Notes |
|---|---|---|---|
| 0 | 0 | 0000 | |
| 1 | 1 | 0001 | |
| 2 | 2 | 0010 | |
| 3 | 3 | 0011 | |
| 4 | 4 | 0100 | |
| 5 | 5 | 0101 | |
| 6 | 6 | 0110 | |
| 7 | 7 | 0111 | |
| 8 | 8 | 1000 | |
| 9 | 9 | 1001 | |
| 10 | A | 1010 | first letter digit |
| 11 | B | 1011 | |
| 12 | C | 1100 | |
| 13 | D | 1101 | |
| 14 | E | 1110 | |
| 15 | F | 1111 | largest single hex digit |
Common byte values (two hex digits = one byte):
| Decimal | Hex | 8-bit Binary | Meaning |
|---|---|---|---|
| 10 | 0x0A | 0000 1010 | Line feed (newline) |
| 32 | 0x20 | 0010 0000 | Space character |
| 65 | 0x41 | 0100 0001 | Letter A in ASCII |
| 97 | 0x61 | 0110 0001 | Letter a in ASCII |
| 255 | 0xFF | 1111 1111 | Maximum value of one byte |
Hex Letters A–F Explained
The part that trips up newcomers: where do the letters come from? Hex needs 16 distinct digits, but we only have ten number symbols (0–9). To fill the last six slots, hex borrows the first six letters of the alphabet:
| Letter | Value |
|---|---|
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
So the letters aren't text—they're digits that stand for the numbers 10 through 15. That's why F is the biggest single hex digit (15), and why 0xFF is 255 (fifteen sixteens plus fifteen ones).
Hex is case-insensitive: A and a mean the same thing, and 0xFF, 0xff, and 0xFf are all identical. Uppercase is traditional in memory dumps and constants; lowercase is common in web colors and hashes. Pick whichever your team prefers and stay consistent.
What is Hexadecimal (Base-16)?
Hexadecimal is a number system that uses 16 digits instead of the 10 we use in everyday life (decimal) or the 2 computers use internally (binary).
The 16 digits are:
Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F
The letters A-F represent values 10-15. They can be uppercase or lowercase—FF and ff are the same.
Counting in Hex
Counting in hex works like decimal, but carries over at 16 instead of 10:
Decimal: 0, 1, 2, ... 9, 10, 11, ... 15, 16, 17, ... 255, 256
Hex: 0, 1, 2, ... 9, A, B, ... F, 10, 11, ... FF, 100
To convert hex to decimal, multiply each digit by powers of 16:
2F (hex) = 2×16¹ + F×16⁰ = 2×16 + 15×1 = 32 + 15 = 47 (decimal)
FF (hex) = 15×16 + 15×1 = 240 + 15 = 255 (decimal)
100 (hex) = 1×256 + 0×16 + 0×1 = 256 (decimal)
Why Hex is Useful for Computers
The magic of hex: each hex digit represents exactly 4 binary bits.
Hex: 0 1 2 3 4 5 6 7
Binary: 0000 0001 0010 0011 0100 0101 0110 0111
Hex: 8 9 A B C D E F
Binary: 1000 1001 1010 1011 1100 1101 1110 1111
This makes hex perfect for representing bytes:
- A byte is 8 bits
- 8 bits = 2 hex digits
- Much easier to read
FFthan11111111
Hex Colors in Web Development
The most common hex encounter for web developers: color codes.
color: #FF5733;
background-color: #3498DB;
A hex color breaks down into Red, Green, and Blue components:
#FF5733
││││││
RR GG BB
Red: FF = 255
Green: 57 = 87
Blue: 33 = 51
Each component ranges from 00 (0, none) to FF (255, maximum). To turn a hex color into RGB values (or the other way around) without doing the math by hand, use the Hex↔RGB color converter.
Common Colors
| Color | Hex | RGB |
|---|---|---|
| Black | #000000 | rgb(0, 0, 0) |
| White | #FFFFFF | rgb(255, 255, 255) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Green | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Yellow | #FFFF00 | rgb(255, 255, 0) |
| Cyan | #00FFFF | rgb(0, 255, 255) |
| Magenta | #FF00FF | rgb(255, 0, 255) |
| Gray | #808080 | rgb(128, 128, 128) |
Shorthand Colors
When each component uses doubled digits, you can use 3-digit shorthand:
#FF5533 → #F53
#AABBCC → #ABC
#000000 → #000
The browser expands each digit: #F53 becomes #FF5533.
8-Digit Hex (with Alpha)
Modern browsers support alpha (transparency) in hex:
background: #FF573380; /* 50% transparent orange */
The last two digits are alpha: 00 (transparent) to FF (opaque).
Hex in Memory Addresses
Memory locations are shown in hex:
0x00000000 - Start of memory
0x7FFFFFFF - ~2GB mark
0xFFFFFFFF - 4GB (32-bit limit)
0xFFFFFFFFFFFFFFFF - 64-bit maximum
The 0x prefix indicates hexadecimal in most programming languages. Network values are often shown in hex too—an IPv4 address, for example, is just four bytes, so you can express it as eight hex digits with the IP to Hex converter.
When debugging, you might see:
Segmentation fault at 0x0000000000401234
Stack pointer: 0x7FFE12345678
Hex makes these large numbers manageable.
Reading Hex Dumps
Hex dumps show file or memory contents in a readable format:
00000000: 4865 6c6c 6f20 576f 726c 640a Hello World.
00000010: 5468 6973 2069 7320 6120 7465 7374 This is a test
The left column shows the offset (position), the middle shows hex values, and the right shows ASCII representation. Non-printable characters appear as dots. If you want to try this yourself, the Hex Encoder/Decoder converts text to hex bytes and back. To see which byte maps to which character, keep the ASCII table and Unicode character reference handy—and for how bytes become letters across encodings, see Character Encoding: ASCII, Unicode & UTF-8.
Converting Between Hex, Binary, and Decimal
Quick Mental Math
Hex to binary: Replace each hex digit with 4 bits
A3 → 1010 0011Binary to hex: Group bits by 4, convert each group
11110000 → F0Hex to decimal: Multiply by position values
2A → 2×16 + 10 = 42
In Code
// JavaScript
parseInt('FF', 16) // 255
(255).toString(16) // "ff"
// Python
int('FF', 16) # 255
hex(255) # '0xff'
format(255, 'x') # 'ff'
// C/C++
int x = 0xFF; // 255
printf("%X", 255); // FF
Hex in UUIDs and Hashes
UUIDs (Universally Unique Identifiers) are written in hex:
550e8400-e29b-41d4-a716-446655440000
Hash values are hex strings:
MD5: d41d8cd98f00b204e9800998ecf8427e
SHA-1: da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA-256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Common Hex Values to Recognize
| Value | Decimal | Significance |
|---|---|---|
| 0x00 | 0 | Null, minimum byte |
| 0x0A | 10 | Line feed (LF) |
| 0x0D | 13 | Carriage return (CR) |
| 0x20 | 32 | Space |
| 0x30 | 48 | ASCII '0' |
| 0x41 | 65 | ASCII 'A' |
| 0x61 | 97 | ASCII 'a' |
| 0x7F | 127 | DEL, max ASCII |
| 0xFF | 255 | Maximum byte |
| 0xFFFF | 65535 | Max 16-bit |
| 0xDEADBEEF | 3735928559 | Debug marker |
| 0xCAFEBABE | 3405691582 | Java class file magic |
Programmers often use memorable hex values like DEADBEEF, CAFEBABE, FEEDFACE as markers or test values.
Hex in URLs and Encoding
URL encoding uses hex:
Space → %20
? → %3F
& → %26
The number after % is the hex ASCII value of the character.
Practical Tips
- Learn the powers of 16: 16, 256, 4096, 65536
- Memorize key values: FF=255, 80=128, 64=100 decimal
- Use programmer calculators: Most OS calculators have a programmer mode
- Read nibbles: Process hex 2 digits at a time (1 byte)
- Watch for the 0x prefix:
0x10is 16, not 10
Frequently Asked Questions
What is hexadecimal code?
Hexadecimal code is any number written in base 16—a system that uses sixteen digits: 0–9 for zero through nine, and the letters A–F for ten through fifteen. It's popular in computing because each hex digit maps neatly onto exactly 4 bits of binary, making it a compact, readable shorthand for the raw bits and bytes a computer works with. A hex "code" might be a color like #FF5733, a byte like 0x41, or a long hash string—all are just base-16 numbers.
How do you read hex?
Read hex digit by digit, left to right, with the leftmost digit carrying the most weight—just like decimal. First, spot the marker that tells you it's hex: a 0x prefix in code, a # for colors, or a % in URLs. Then convert each digit (remember A=10 through F=15) and multiply by its place value (ones, sixteens, 256s…). For a byte like 0x3A, the left digit is the high nibble (3 × 16 = 48) and the right digit is the low nibble (A = 10), giving 48 + 10 = 58. Reading two digits at a time is easiest, because two hex digits equal exactly one byte.
What is the hex value for the letter A?
This depends on which sense of "A" you mean, and both are worth knowing:
- As an ASCII character, the capital letter
Ahas the value0x41, which is 65 in decimal. That's why you'll see41in a hex dump wherever the text contains anA. (Lowercaseais0x61= 97.) - As a hex digit, the symbol
Asimply stands for the number 10—the first of the letter digits that fill hex's slots for ten through fifteen.
So "the hex value for A" is 0x41 if you're asking how the letter A is stored, but A itself equals 10 when it's being used as a digit inside a hex number. Check the ASCII table for the full character-to-hex mapping.
Why do programmers use hex?
Because it's a compact, human-friendly stand-in for binary. Computers store everything as bits, but reading long strings of 0s and 1s is slow and error-prone. Since one hex digit equals exactly 4 bits and two hex digits equal one byte, hex expresses the same values in a quarter of the characters while still lining up cleanly with the machine's bit groupings—something decimal can't do. That's why hex shows up in colors, memory addresses, byte values, MAC addresses, hashes, and UUIDs.
What do the letters in hex mean?
The letters A–F are digits, not text. Hex needs sixteen distinct symbols, but our number system only supplies ten (0–9), so hex borrows the first six letters of the alphabet to represent the remaining values: A=10, B=11, C=12, D=13, E=14, and F=15. They're case-insensitive, so A and a mean the same thing.
Summary
Hexadecimal is the developer's number system:
- 16 digits: 0-9 and A-F
- Each digit = 4 binary bits
- Perfect for representing bytes compactly
- Used in colors, memory, hashes, UUIDs, and more
Once you're comfortable with hex, you'll see it everywhere—and wonder how you ever managed without it.
Need to convert hex values? Try our Hex Encoder/Decoder or Hex↔RGB Color Converter!