Hexadecimal Explained: Why Programmers Count in Base 16
Published 2026-05-22
Color codes like #FF6B35, memory addresses like 0x7FFE, hashes, MAC addresses, error codes — all of them are written in hexadecimal. For newcomers, base 16 looks intimidating, but it is one of the most useful and approachable ideas in computing once it clicks. Here is the whole concept, from the ground up.
Counting beyond ten
We count in base 10 because we have ten fingers: the digits 0–9, and when we run out we add a new place (9 → 10). Hexadecimal is base 16: it has sixteen digits. Since we only have ten number symbols, hex borrows the first six letters of the alphabet for the rest:
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
So A is ten, F is fifteen, and the next number after F is 10 in hex — which equals sixteen in decimal. To avoid confusion, hex values are usually prefixed with 0x (as in 0x10) or # for colors.
Converting hex to decimal
Each position in a hex number is a power of 16, read right to left: the rightmost digit is the 1s place, then 16s, then 256s, and so on. Take 0x2F:
2F = (2 × 16) + (15 × 1)
= 32 + 15
= 47
And 0xFF, the famous maximum of a single byte:
FF = (15 × 16) + (15 × 1) = 240 + 15 = 255
Why hex and binary are best friends
Here is the reason hex dominates programming: one hex digit represents exactly four binary digits (bits). Four bits can hold sixteen values — precisely the range of one hex digit. That makes the conversion mechanical:
Binary: 1111 1111
Hex: F F = 0xFF
Binary: 0010 1010
Hex: 2 A = 0x2A
A byte is eight bits, so it is always exactly two hex digits. This is why memory dumps, color channels, and hashes are shown in hex: it is a compact, lossless shorthand for binary that humans can actually read. Writing 0xFF is far easier than 11111111, and you can convert between them in your head once you memorize the sixteen patterns.
Where you will meet hexadecimal
- Colors:
#FF6B35is three bytes — redFF(255), green6B(107), blue35(53). - Memory addresses: debuggers and low-level code show locations like
0x7FFE3210. - Hashes and checksums: an MD5 or SHA value is just a long hex string.
- Character codes: Unicode code points are written as
U+1F600in hex. - Permissions and flags: bit masks are often expressed in hex for compactness.
Octal, the third base
You will occasionally see base 8 (octal), most famously in Unix file permissions: chmod 755. Each octal digit encodes three permission bits for owner, group, and others. Octal groups bits in threes the way hex groups them in fours.
The fastest way to build intuition is to convert numbers back and forth and watch the patterns. The converter below shows binary, octal, decimal, and hex side by side — type in any field and the others update instantly.