Hexadecimal, binary and decimal: a guide to understanding them
If you program or study computing, sooner or later you meet numbers in binary or hexadecimal: colours like #FF6600, permissions like 755 or memory addresses like 0xDEADBEEF. This guide explains what these number systems are, why they exist and how to convert between them by hand, with fully worked examples.
Why different systems exist
The decimal system (base 10) is the one we use daily — most likely because we have ten fingers. Computers, on the other hand, work in binary (base 2: only 0 and 1) because their circuits can reliably distinguish two electrical states: voltage present or absent. Each of those binary digits is a bit, and eight bits form a byte.
The trouble with binary is that it gets very long for humans: the number 2026 needs eleven bits. That is where hexadecimal (base 16) comes in, using the digits 0–9 plus the letters A–F. Its superpower is that each hex digit corresponds to exactly 4 bits, so it works as shorthand for binary: a full byte is always written with exactly two hex digits. That is why you see it in web colours, memory dumps and MAC addresses.
The key idea: positional notation
In any base, the value of a digit depends on its position. In decimal, 3,482 means 3×1,000 + 4×100 + 8×10 + 2×1: each position is worth ten times the one to its right. In binary each position is worth twice the previous one (1, 2, 4, 8, 16, 32, 64, 128…), and in hexadecimal, sixteen times (1, 16, 256, 4,096…).
With that idea, the same number can be written in all three bases:
- Decimal: 173 = 1×100 + 7×10 + 3×1
- Binary: 10101101 = 128 + 32 + 8 + 4 + 1 = 173
- Hexadecimal: AD = 10×16 + 13 = 173
Three representations, one value. No base is "more correct" than another: each is convenient in its own context.
How counting works in each base
This equivalence table is worth memorising at least up to 15, because it is what lets you translate between binary and hexadecimal at a glance:
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 12 | 1100 | C |
| 15 | 1111 | F |
| 16 | 10000 | 10 |
| 45 | 101101 | 2D |
| 255 | 11111111 | FF |
| 2026 | 11111101010 | 7EA |
Careful: "10" does not mean the same thing in every base. In binary it is two, in decimal ten and in hexadecimal sixteen. That is why programming languages use prefixes: 0b1010 for binary and 0xA for hexadecimal.
Converting step by step
Decimal to binary: repeated division
Divide by 2 over and over, note the remainders, then read them from bottom to top. Let's convert 2026:
2026 in binary
- 2026 ÷ 2 = 1013, remainder 0
- 1013 ÷ 2 = 506, remainder 1
- 506 ÷ 2 = 253, remainder 0 · 253 ÷ 2 = 126, remainder 1
- 126 ÷ 2 = 63, remainder 0 · 63 ÷ 2 = 31, remainder 1
- 31 ÷ 2 = 15, remainder 1 · 15 ÷ 2 = 7, remainder 1
- 7 ÷ 2 = 3, remainder 1 · 3 ÷ 2 = 1, remainder 1 · 1 ÷ 2 = 0, remainder 1
Reading the remainders from last to first: 11111101010. So 2026 = 0b11111101010.
Binary to decimal: sum of powers
Give each bit its positional value starting with 1 on the right and doubling as you move left; then add up the positions holding a 1. For 10101101: 128 + 32 + 8 + 4 + 1 = 173.
Binary to hexadecimal (and back): groups of 4 bits
Group the bits in fours starting from the right and translate each group using the table above. If the leftmost group is incomplete, pad it with zeros:
11111101010 → 0111 1110 1010 → 7 E A → 0x7EA
The reverse trip is just as direct: each hex digit expands to its 4 bits. This instant translation is exactly why hexadecimal is the preferred base for displaying binary data.
Decimal to hexadecimal: division by 16
Same method as with binary, but dividing by 16: 2026 ÷ 16 = 126 remainder 10 (A); 126 ÷ 16 = 7 remainder 14 (E); 7 ÷ 16 = 0 remainder 7. Reading bottom-up: 7EA. It matches the bit-grouping result, as it should. You can check any of these exercises with our hex-binary converter.
Where you meet them in practice
- Web colours: #FF6600 is three bytes in hex — red 0xFF (255), green 0x66 (102) and blue 0x00 (0). A vivid orange.
- MAC and IPv6 addresses: written in hexadecimal precisely because it packs many bits into little space.
- Unix/Linux permissions: the famous chmod 755 uses base 8 (octal), where each digit encodes 3 permission bits.
- Debugging and memory: addresses and memory dumps are shown in hex (hence celebrity values like 0xDEADBEEF).
- Networking: realising that 255 is 11111111 (a byte with all bits set) instantly demystifies subnet masks.
Common conversion mistakes
- Reading the remainders in the wrong order: in repeated division, the first remainder is the least significant bit. Read bottom-up.
- Grouping from the left: the 4-bit groups form from the right; starting on the left gives a wrong answer unless the length is a multiple of 4.
- Forgetting the base context: seeing "10" and assuming ten. Without a prefix (0x, 0b) or context, a number is ambiguous.
- Worrying about letter case: 0xff and 0xFF are the same number; capitalisation of A–F never changes the value.
- Dropping leading zeros: when expanding hex to binary, every digit produces exactly 4 bits. 0x2D is 0010 1101, not a trimmed 10 1101.
Frequently asked questions
Do computers calculate in hexadecimal?
No: internally everything is binary. Hexadecimal is just a convenient notation so humans can read and write those bits without slipping up.
Why does 255 appear so often in computing?
Because it is the maximum value of one byte: eight bits all set to 1 (11111111 = 0xFF). That is why RGB colour channels run from 0 to 255 and why it shows up in network masks.
What is octal still used for?
Its main modern use is file permissions on Unix/Linux systems, because each octal digit encodes the 3 bits for read, write and execute.
How can I check my conversions?
Do the exercise by hand and verify the result with a tool: if the decimal value matches in both directions, your conversion is correct.
Convert between hexadecimal, binary, octal and decimal instantly, and check your practice exercises.
Hex-binary converter →