What is hexadecimal?
Hexadecimal, or hex, is the base-16 number system. It uses the digits 0 to 9 and the letters A to F. Try a hex number in the box, then read on for how it works.
Prefixes 0b, 0o, 0x and spaces or underscores between digits are fine. A point starts the fraction.
The short answer
Hexadecimal counts in sixteens instead of tens. It needs sixteen digit symbols, so after 0 to 9 it uses A for 10, B for 11, up to F for 15. The next number after F is 10, which in hex means one sixteen and no ones.
Programmers use hex because one hex digit is exactly four bits. A byte, eight bits, is always two hex digits, from 00 to FF. That makes long binary numbers short and easy to read: 1111 1111 is just FF.
Hex chart: 0 to F
| Decimal | Hex | Binary |
|---|---|---|
| 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 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Place values in hex
Each place in a hex number is worth 16 times the place to its right: 1, 16, 256, 4096 and so on. To find the value, multiply each digit by its place value and add.
For 2AF: 2 × 256 = 512, A (10) × 16 = 160, and F (15) × 1 = 15. That adds up to 687. The hex to decimal converter shows this working for any number.
| Digit | Place value | Digit × place value |
|---|---|---|
| 2 | 162 = 256 | 2 × 256 = 512 |
| A (10) | 161 = 16 | 10 × 16 = 160 |
| F (15) | 160 = 1 | 15 × 1 = 15 |
Counting in hex
Counting goes 0, 1 … 9, A, B, C, D, E, F, then 10. After 1F comes 20, after FF comes 100, and after FFF comes 1000. Each time a place passes F it goes back to 0 and carries 1 to the left, the same way 9 rolls over to 10 in decimal.
Why do programmers use hex?
Computers work in binary, but long strings of 0s and 1s are hard to read and easy to miscopy. Because 16 is 2 × 2 × 2 × 2, each hex digit stands for exactly one group of four bits, called a nibble.
You can turn binary into hex by grouping the bits in fours, and back again by writing each hex digit as four bits. Decimal has no shortcut like that.
Where do you see hexadecimal?
| Where | Example | What it means |
|---|---|---|
| Web colours | #FF8000 | Three bytes: red FF (255), green 80 (128), blue 00 (0) |
| Numbers in code | 0xFF | The 0x prefix marks a hex number in JavaScript and many other languages |
| Bytes in a file | 48 65 6C 6C 6F | Each byte as two hex digits; these five spell “Hello” in ASCII |
| Character codes | 41 | The ASCII code for “A” (65 in decimal) |
Converting hex
- Hex to decimal: multiply each digit by its place value and add, as above.
- Decimal to hex: divide by 16 repeatedly and read the remainders from the bottom up.
- Hex to binary and binary to hex: swap each hex digit for four bits, or each group of four bits for one hex digit.
- Hex to text: read each pair of hex digits as one byte and look it up in the ASCII table.
Sources and method
- W3C CSS Color Module Level 3 (Recommendation, 18 January 2022), section 4.2.1: RGB colour values in #rrggbb hexadecimal notation. Checked 2026-11-25.
- ECMA-262, ECMAScript Language Specification, section 12.9.3 Numeric Literals: the 0b, 0o and 0x prefixes for binary, octal and hex. Checked 2026-11-25.
- RFC 20 (STD 80), ASCII format for network interchange, section 4: the 128 ASCII codes and control-character names. Checked 2026-11-25.
Conversions use exact whole-number arithmetic (JavaScript BigInt), so long numbers keep every digit. Fractions are kept as exact ratios; when the digits repeat, the repeating block is found and marked instead of rounded.
Questions
Why does hexadecimal use letters?
Base 16 needs sixteen single-digit symbols. The digits 0 to 9 give ten, so A to F stand for 10 to 15.
What does 0x mean in front of a number?
It marks the number as hexadecimal. In JavaScript, 0x is one of three prefixes, with 0b for binary and 0o for octal.
Is hex the same as base 16?
Yes. Hexadecimal, hex and base 16 all mean the same number system.
What is FF in decimal?
255: F (15) × 16 + F (15) = 240 + 15. It is the largest value one byte can hold.