All guides

What Is Hexadecimal and Why Do Programmers Live in It?

Sixteen digits, four bits each

Hexadecimal counts in sixteens. After 9 it borrows letters: A is 10, B is 11, and so on up to F at 15. Its magic property is that one hex digit is exactly four binary digits, no remainder and no rounding. A byte of eight bits is always exactly two hex digits, from 00 to FF. That tidy fit is the whole reason hex exists in computing. Binary is accurate but unwieldy; decimal is familiar but slices bytes awkwardly. Hex is the compromise programmers settled on: compact enough to print, aligned enough with the hardware that conversion is a simple grouping exercise rather than real arithmetic.

Where you meet hex in the wild

Web colours are hex: the code FF8800 describes red, green and blue values as three bytes. Memory addresses in error messages and debuggers are hex, often with a 0x prefix to warn you, as in 0x3F7A. Network card MAC addresses are six hex bytes separated by colons. File signatures, the magic numbers that identify file types, are documented in hex, and so are the dumps you get from examining a file byte by byte. Even emoji and characters have hex code points in Unicode. Once you can read hex as bytes, a surprising amount of technical writing stops looking like static and starts reading as plain numbers.

Converting without a calculator

To read hex by hand, expand each digit into its value and multiply by powers of sixteen, or expand into binary groups of four and then read the binary. The value 2F is 2 times 16 plus 15, which is 47. Longer values chain the same way. Going the other direction, the grouping trick is fastest: write the number in binary, split it into fours from the right, and translate each group. The digits worth memorising are the landmarks: 10 hex is 16, FF is 255, 100 is 256, FFF is 4095 and FFFF is 65535. The converter on this page handles any length and also shows a six digit value as its RGB colour, which is a pleasant way to explore. A last practical tip: when you copy a hex value from an error message or a log, search for it exactly as written, including the 0x prefix in a second search without it. Documentation and forums split between the two habits, and the answer you need may be filed under either spelling. And when a colour code misbehaves on a website, count its digits: five or seven digits means a typo, because valid hex colours are three, four, six or eight.

Try the calculator

The free tool that goes with this guide:

Convert hexadecimal