Hexadecimal – "hex" for short – is everywhere in computing: web colour codes like #FF5733, memory addresses, MAC addresses and error codes. It packs binary data into a short, readable form. If you are learning how to convert decimal to hexadecimal, this guide walks through the method, shows how to go back the other way and explains how hex colour codes work.
Hexadecimal digits
Hex is base 16, so it needs sixteen digits. After 0–9 it uses letters:
- A = 10
- B = 11
- C = 12
- D = 13
- E = 14
- F = 15
So "F" means fifteen, and "10" in hex means sixteen.
Decimal to hex: divide by 16
- Divide the number by 16 and note the remainder.
- Divide the result again by 16, noting each remainder.
- Continue until the result is 0.
- Write the remainders from bottom to top, using letters for 10–15.
Example 1: 255
255 ÷ 16 = 15 remainder 15 (F) 15 ÷ 16 = 0 remainder 15 (F) Answer: FF
Example 2: 500
500 ÷ 16 = 31 remainder 4 31 ÷ 16 = 1 remainder 15 (F) 1 ÷ 16 = 0 remainder 1 Answer: 1F4
Example 3: 2024
2024 ÷ 16 = 126 remainder 8 126 ÷ 16 = 7 remainder 14 (E) 7 ÷ 16 = 0 remainder 7 Answer: 7E8
Hex to decimal: multiply by powers of 16
Each place in hex is worth 16 times the place to its right: 1, 16, 256, 4096 and so on.
1F4 = 1 × 256 + 15 × 16 + 4 × 1 = 256 + 240 + 4 = 500
7E8 = 7 × 256 + 14 × 16 + 8 = 1792 + 224 + 8 = 2024
The binary shortcut
Every hex digit is exactly four binary digits, so you can convert between binary and hex by grouping bits in fours: 1111 1111 = FF, 0011 0101 = 35. This is why programmers prefer hex – it is a compact way to write binary. See how to convert binary to octal for the same grouping idea with threes, and how to convert binary to decimal for the basics.
How hex colour codes work
A web colour such as #FF5733 is three hex pairs: red, green and blue, each from 00 (0) to FF (255).
- FF = 255 red
- 57 = 87 green
- 33 = 51 blue
So #FF5733 is a bright orange-red. #000000 is black, #FFFFFF is white and #808080 is a mid grey. Pick and convert colours with the Color Picker, grab exact colours from a photo with the Image Color Picker, or get inspiration from the Random Color Generator.
Where else you will see hex
- Error codes such as 0x80070005 on Windows
- MAC addresses like 00:1A:2B:3C:4D:5E
- Unicode characters, such as U+20A6 for the naira sign
- Memory addresses in debugging tools
Common mistakes
- Writing remainders top to bottom instead of bottom to top.
- Forgetting to swap 10–15 for A–F.
- Confusing hex "10" (sixteen) with decimal ten.
Frequently asked questions
Why do programmers use hexadecimal instead of decimal? Because each hex digit maps exactly to four bits, long binary values become short and readable. A 32-bit value needs only eight hex digits.
Is hex case-sensitive? No. "ff", "FF" and "Ff" all mean 255. Colour codes and programming languages accept either.
What does the 0x prefix mean? It simply marks a number as hexadecimal in code, so 0x1F4 means hex 1F4 (500 in decimal), not a decimal number.
What is the largest two-digit hex number? FF, which is 255 – the maximum value of one byte.
Summary
Now you know how to convert decimal to hexadecimal: divide by 16, record the remainders as hex digits and read them upwards. To go back, multiply each digit by its power of 16 and add. Check your answers instantly with the free Number Base Converter, which also shows binary and octal.