How Does Hexadecimal Work: Colors, Memory & Binary

Hexadecimal is a base-16 number system that uses 16 symbols instead of the 10 you’re used to in everyday counting. The digits 0 through 9 work the same way they do in decimal, and then the letters A through F represent the values 10 through 15. That’s the entire alphabet of hex: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. It exists because it’s a remarkably efficient shorthand for the binary code that computers actually run on.

Why 16 Symbols Instead of 10

Normal counting (decimal) is base-10. Each digit position can hold one of 10 values, and when you run out, you carry over to the next column. The number 42 means four tens plus two ones. Hexadecimal works the same way, except each position holds one of 16 values, and the columns represent powers of 16 instead of powers of 10.

In hex, the rightmost digit is the ones place (16⁰ = 1), the next column to the left is the sixteens place (16¹ = 16), the next is the two-hundred-fifty-sixes place (16² = 256), and so on. So the hex number 2F means: 2 × 16 plus F × 1. Since F equals 15, that’s 32 + 15 = 47 in decimal. Once you see that each letter is just a stand-in for a two-digit decimal number (A=10, B=11, C=12, D=13, E=14, F=15), the math is no different from what you already know.

The Connection to Binary

Computers think in binary, ones and zeros. A single binary digit (bit) is either 0 or 1. Group four bits together and you can represent 16 unique values, from 0000 (zero) to 1111 (fifteen). That’s exactly the range of one hexadecimal digit. This isn’t a coincidence. Because 16 is a power of 2 (2⁴ = 16), each hex digit maps perfectly onto a group of four bits.

This makes conversion between hex and binary almost trivially easy. To turn the hex value 3C into binary, you convert each digit separately: 3 becomes 0011, C (which is 12) becomes 1100. String them together and you get 00111100. No complicated math, no division, just a direct swap. That’s the core reason hex became the standard shorthand in computing. Writing out long strings of ones and zeros is error-prone and hard to read. Hex compresses them by a factor of four without losing the direct relationship to the underlying bits.

What Two Hex Digits Can Do

Two hexadecimal digits together represent eight bits, which is one byte. The lowest value is 00 (zero) and the highest is FF. That F in the sixteens place is worth 15 × 16 = 240, and the F in the ones place adds another 15, giving a maximum of 255. This means two hex characters can express any value a single byte can hold, from 0 to 255. Since the byte is the fundamental unit of computer memory, this pairing comes up constantly.

Hex Color Codes

If you’ve ever seen a color written as #FF5733 on a website, you’ve already used hexadecimal. That six-character string is really three pairs of hex digits, each controlling one color channel: red, green, and blue. The first pair (FF) sets red intensity, the second pair (57) sets green, and the third pair (33) sets blue. Each pair ranges from 00 (none of that color) to FF (maximum intensity, 255).

Some examples make this intuitive. Pure red is #FF0000: red maxed out, green and blue at zero. Pure white is #FFFFFF: all three channels at full blast. Black is #000000: everything off. A color like #888888, where all three values are equal and sitting at the midpoint, gives you a medium gray. Bump all three up to #BBBBBB and the gray gets lighter. The system gives web designers precise control over 16.7 million possible colors (256 × 256 × 256) using just six compact characters.

Memory Addresses

When a computer stores data in memory, every location has a numerical address. These addresses are conventionally written in hexadecimal. A 32-bit system has addresses up to about 4.3 billion. In binary, that’s 32 digits long. In hex, it’s only 8 characters (like 0x7FFF0000). The “0x” prefix is a common convention that tells you the number that follows is hexadecimal, not decimal.

Programmers and system tools display memory addresses in hex because it’s compact enough to scan quickly but still maps directly to the binary the hardware uses. If you see an error message with a string like 0x0000005C, that’s a memory address. Each pair of characters in it corresponds to one byte, which makes it straightforward to calculate offsets and spot patterns when debugging.

IPv6 Addresses

Network addresses are another place hex shows up in everyday technology. The newer internet addressing system, IPv6, uses 128-bit addresses. Writing those out in decimal would be unwieldy. Instead, IPv6 breaks the address into eight groups of four hex characters, separated by colons. A full address looks like this: 2001:0db8:0000:0000:0000:ff00:0042:8329.

Even in hex, that’s a lot of characters, so IPv6 has shorthand rules. You can drop leading zeros within each group (0042 becomes just 42), and you can replace consecutive groups of all zeros with a double colon. That example address shortens to 2001:db8::ff00:42:8329. The double colon can only appear once in an address so there’s no ambiguity about how many zero groups it replaces. Without hex, expressing 128-bit addresses in any readable form would be nearly impossible.

How to Convert Hex to Decimal

Take each digit, multiply it by the power of 16 that matches its position (starting from 0 on the right), and add the results. For a hex value like 1A3:

  • 3 is in position 0: 3 × 16⁰ = 3 × 1 = 3
  • A is in position 1: 10 × 16¹ = 10 × 16 = 160
  • 1 is in position 2: 1 × 16² = 1 × 256 = 256

Add them up: 256 + 160 + 3 = 419. So 1A3 in hex equals 419 in decimal.

Going the other direction, you divide the decimal number by 16 repeatedly and keep track of the remainders. Each remainder becomes one hex digit, read from bottom to top. For 419: 419 ÷ 16 = 26 remainder 3. Then 26 ÷ 16 = 1 remainder 10 (which is A). Then 1 ÷ 16 = 0 remainder 1. Reading the remainders upward gives you 1A3. In practice, most people use a calculator for large numbers, but understanding the process helps you read and reason about hex values when you encounter them.

Why Not Just Use Decimal Everywhere

Decimal doesn’t align neatly with binary. Ten isn’t a power of two, so converting between decimal and binary requires actual division and multiplication. Hex, because it’s based on 16 (a power of 2), lets you move back and forth with simple substitution. Every hex digit is exactly four bits, every two hex digits are exactly one byte. That clean mapping means fewer mistakes, shorter notation, and faster comprehension for anyone working close to the hardware. It’s not that hex is better for everyday math. It’s that hex is better for representing the data structures computers actually use.