The hexadecimal number system is a base-16 counting system that uses sixteen symbols: the digits 0 through 9 and the letters A through F. Where our everyday decimal system has ten possible values per digit (0–9), hexadecimal extends that to sixteen, with A representing 10, B representing 11, and so on up to F representing 15. It’s the standard shorthand for representing binary data in computing, and you encounter it in everything from color codes on websites to memory addresses in software.
How Base-16 Counting Works
In any number system, each digit’s position represents a power of the base. In decimal (base-10), the number 523 means 5×100 + 2×10 + 3×1. Hexadecimal works the same way, but with powers of sixteen. The hex number 2F3 means 2×256 + 15×16 + 3×1, which equals 755 in decimal. The “F” stands for 15, so it occupies the sixteens column and contributes 240 to the total.
The sixteen symbols and their decimal equivalents are:
- 0–9 represent 0–9 (same as decimal)
- A = 10
- B = 11
- C = 12
- D = 13
- E = 14
- F = 15
Once you reach F in a single column, the next value (16) rolls over to “10” in hex, just like 9 rolls to 10 in decimal. So hexadecimal 10 equals decimal 16, hexadecimal 20 equals decimal 32, and hexadecimal FF equals decimal 255.
Why Computers Use Hexadecimal
Computers process everything in binary, long strings of ones and zeros. Binary is efficient for circuits but painful for humans to read. A single byte of data is eight binary digits long (like 11010110), and large values quickly become unmanageable walls of bits. Hexadecimal solves this because one hex digit maps perfectly to exactly four binary digits, a group sometimes called a “nibble.” That means any byte can be written as just two hex characters instead of eight binary ones.
This isn’t a coincidence. Sixteen is 2 to the fourth power, so every possible combination of four bits (0000 through 1111) corresponds to exactly one hex digit (0 through F). Converting between the two is mechanical: you simply swap each hex digit for its four-bit equivalent, or group binary digits into fours and replace each group. The number 11010110 in binary splits into 1101 (D) and 0110 (6), giving you D6 in hex. No math required, just pattern matching.
Two hex digits cover all values from 00 to FF, which is 0 to 255 in decimal. That range is exactly one byte. This is why hex became the universal language for expressing raw computer data. It’s compact enough to read at a glance but maps directly to the binary underneath.
Where You’ll See Hex in Practice
Color Codes
If you’ve ever customized a website or picked a color in a design tool, you’ve used hex. A hex color code is a six-character string preceded by a # symbol, like #FF5733. The six characters break into three pairs: the first two represent the red intensity, the middle two represent green, and the last two represent blue. Each pair ranges from 00 (no intensity) to FF (full intensity, or 255). So #FF0000 is pure red, #00FF00 is pure green, and #FFFFFF is white because all three channels are at maximum. This format packs three separate values (red, green, blue) into a single compact code.
Memory Addresses
Every byte stored in your computer’s memory has a numbered address. These addresses are displayed in hexadecimal because they can be enormous in decimal but stay readable in hex. A memory address like 0xf79c14 is far easier to scan than its binary equivalent, and programmers can quickly estimate its position in memory by looking at the leading digits. Error messages, debugging tools, and system logs all report addresses this way.
Programming Languages
Different programming languages signal “this is a hex value” with different markers. C, C++, Python, Java, and JavaScript all use the prefix 0x, so you’d write 0xFF for the decimal value 255. Assembly language often uses a suffix “h” instead, like 0FFh. Some older systems used a dollar sign prefix. Regardless of the notation, the underlying value is the same. There’s no restriction on leading zeros, so 0x00FF and 0xFF represent the same number.
Converting Between Hex and Decimal
To convert a hex number to decimal, multiply each digit by its positional power of sixteen and add the results. Take hex 1A3: the 1 sits in the 256s column (16²), the A (10) sits in the 16s column, and the 3 sits in the 1s column. That gives you 1×256 + 10×16 + 3×1 = 419.
Going the other direction, divide the decimal number by 16 repeatedly. At each step, the remainder becomes the next hex digit (starting from the right), and the quotient carries forward. For 419: dividing by 16 gives 26 remainder 3 (rightmost digit is 3), then 26 divided by 16 gives 1 remainder 10 (next digit is A), and 1 divided by 16 gives 0 remainder 1 (leftmost digit is 1). Result: 1A3.
Converting Between Hex and Binary
This conversion is simpler because it’s just a substitution table. Each hex digit corresponds to a fixed four-bit pattern:
- 0 = 0000, 1 = 0001, 2 = 0010, 3 = 0011
- 4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111
- 8 = 1000, 9 = 1001, A = 1010, B = 1011
- C = 1100, D = 1101, E = 1110, F = 1111
To convert hex to binary, replace each digit with its four-bit group. The hex value 5B becomes 0101 1011. To go from binary to hex, split the binary number into groups of four starting from the right, padding with leading zeros if needed, and substitute each group. The binary number 110111010 would be padded to 0001 1011 1010, giving hex 1BA.
Hex Arithmetic
Addition and subtraction in hex follow the same column-by-column rules you learned in grade school, just with a wider set of digits. When adding two hex digits in a column, if the sum is less than 16, you write it as a single hex digit. If the sum is 16 or more, you subtract 16, write down the remainder, and carry 1 to the next column. For example, adding hex 5BAF + 0161: in the rightmost column, F (15) + 1 = 16, which is 0 with a carry of 1. The carry ripples leftward through each column.
Subtraction works in reverse. When a digit is too small to subtract from, you borrow 1 from the column to the left. That borrowed 1 is worth 16 in the current column (not 10, as it would be in decimal). So borrowing turns a 0 into 16, or a 5 into a 21 (5 + 16).
Origins of the A–F Notation
The word “hexadecimal” dates to 1950, when it described the notation used for programming the Standards Eastern Automatic Computer (SEAC), built by the National Bureau of Standards in Maryland. The Bureau chose the digits 0–9 and the letters A–F as the sixteen symbols, and that convention stuck. A common claim credits IBM with coining the term, but that’s false. IBM popularized hex through its widespread mainframe computers in the 1960s, but the notation and the name were already established.

