# Binary, hex and decimal: counting in bases 2, 10 and 16

> Computers store everything as bits, but people read decimal, and programmers often use hexadecimal as a shortcut. The same number, 202, is 11001010 in binary and CA in hex. This guide shows how to convert between them by hand, why one hex digit equals four bits, and where you meet these systems every day.

Published 2026-10-08 by Toolcloak. 4 minute read. Original: https://toolcloak.pages.dev/articles/binary-hex-and-decimal-counting-in-bases-2-10-and-16
Related free tool: [Number Base Converter](https://toolcloak.pages.dev/tools/number-base)

You count in tens because you have ten fingers. A computer counts in twos because a switch has two states. Hexadecimal, base 16, sits between them as a tidy way for people to write long strings of bits. None of these systems is harder than decimal. They only change what each position is worth.

> **In short**
> - A **base** is how many symbols a number system uses: 10 for decimal, 2 for binary (0 and 1), 16 for hex (0–9 and A–F).
> - In binary each position is worth **double** the one to its right: 128, 64, 32, 16, 8, 4, 2, 1.
> - **One hex digit is exactly four bits**, so a byte (8 bits) is always two hex digits, from 00 to FF.
> - The number **202** is **11001010** in binary and **CA** in hex. All three are the same value.

## Place value: the idea behind every base

In decimal, the number 305 means 3 hundreds, 0 tens and 5 ones. Each place is worth ten times the one on its right. Binary does the same with two. Hex does the same with sixteen.

**What each binary place is worth (8 bits)**

|  | Value |
| --- | --- |
| bit 7 | 128 |
| bit 6 | 64 |
| bit 5 | 32 |
| bit 4 | 16 |
| bit 3 | 8 |
| bit 2 | 4 |
| bit 1 | 2 |
| bit 0 | 1 |

*Every place is double the one to its right. Add up the places that are switched on to get the number. All eight on gives 255.*

## Reading a binary number

Take 11001010. Write the place values above each bit and add the ones that are on.

| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Bit | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
| Counts? | 128 | 64 | – | – | 8 | – | 2 | – |

*128 + 64 + 8 + 2 = 202.*

**202 as eight switches (filled = on)**

| Group | Count |
| --- | --- |
| On: 128 and 64 | bits 7 and 6 |
| Off: 32 and 16 | bits 5 and 4 |
| On: 8 | bit 3 |
| Off: 4 | bit 2 |
| On: 2 | bit 1 |
| Off: 1 | bit 0 |

## Decimal to binary by dividing by 2

To convert, divide by 2 again and again, and write down each remainder. Read the remainders from the last to the first.

**Converting 202 to binary**

1. **202 ÷ 2 = 101.** Remainder 0. This is the last bit (bit 0).
2. **101 ÷ 2 = 50.** Remainder 1.
3. **50 ÷ 2 = 25 · 25 ÷ 2 = 12.** Remainders 0 and 1.
4. **12 ÷ 2 = 6 · 6 ÷ 2 = 3.** Remainders 0 and 0.
5. **3 ÷ 2 = 1 · 1 ÷ 2 = 0.** Remainders 1 and 1. Stop when you reach 0.
6. **Read from the bottom up.** 11001010, which is 202.

Try it: [Number Base Converter](https://toolcloak.pages.dev/tools/number-base). Type a number in any base and see it in binary, octal, decimal and hex at once.

## Why hex exists

Long strings of ones and zeros are hard for people to read and easy to mistype. Hex is a shortcut. Because 16 is 2⁴, one hex digit stands for exactly four bits. You can convert a binary number to hex by splitting it into groups of four from the right.

| Decimal | Binary | Hex | Decimal | Binary | Hex |
| --- | --- | --- | --- | --- | --- |
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | 10 | 1010 | A |
| 3 | 0011 | 3 | 11 | 1011 | B |
| 4 | 0100 | 4 | 12 | 1100 | C |
| 5 | 0101 | 5 | 13 | 1101 | D |
| 6 | 0110 | 6 | 14 | 1110 | E |
| 7 | 0111 | 7 | 15 | 1111 | F |

*Hex uses the letters A to F for the values 10 to 15.*

For 11001010, split into 1100 and 1010. 1100 is C (12) and 1010 is A (10). So the hex is CA. Check it: C × 16 + A = 12 × 16 + 10 = 202.

**The same byte, three ways**

| For people | For machines and programmers |
| --- | --- |
| 202 | 11001010 = 0xCA |
| Decimal, easy to read | Binary shows every bit |
| Hard to see which bits are on | Hex is a short form: two digits per byte |

## How big can a number get?

**The largest value that fits in each size**

|  | Value | Note |
| --- | --- | --- |
| 8 bits (1 byte) | 255 | Hex FF |
| 16 bits | 65,535 | Hex FFFF |
| 32 bits | 4.29 billion | 4,294,967,295 · IPv4 addresses |
| 64 bits | 1.8 × 10¹⁹ | 18,446,744,073,709,551,615 |

*Each extra bit doubles the number of values. n bits can hold 2ⁿ different values, from 0 up to 2ⁿ − 1.*

## Where you meet these every day

- **Web colours.** `#6366f1` is three bytes: 63, 66 and F1 in hex, which are 99, 102 and 241 in decimal. That is red 99, green 102, blue 241. The [contrast checker guide](https://toolcloak.pages.dev/articles/is-your-text-readable-the-contrast-ratio-explained) uses these values.
- **IP addresses.** Each part of 192.168.1.10 is one byte (8 bits). See [what /24 and /26 mean](https://toolcloak.pages.dev/articles/cidr-and-subnets-what-slash-24-slash-26-and-slash-20-really-mean).
- **File permissions.** The chmod number 755 is octal (base 8). Each digit is three bits: 7 is 111 (read, write, execute), 5 is 101 (read and execute).
- **Characters.** The letter A is 65 in decimal, 41 in hex and 01000001 in binary.
- **Hashes.** A SHA-256 hash is 256 bits, shown as 64 hex digits. See [what a hash is](https://toolcloak.pages.dev/articles/what-a-hash-is-and-why-changing-one-letter-changes-everything).

## Quick tips

1. Memorise the place values 1, 2, 4, 8, 16, 32, 64, 128. Everything else is addition.
2. Learn the sixteen four-bit patterns above. Then hex and binary conversions become instant.
3. Write 0x before a hex number in code (0xCA) and 0b before binary (0b11001010) so they are not mistaken for decimal.
4. Check by converting back. If you end up at the number you started with, the conversion is right.

> **Odd-looking numbers are often powers of two:** 256, 512, 1024, 65536. They are 2⁸, 2⁹, 2¹⁰ and 2¹⁶. Once you know that bits double, those numbers stop looking arbitrary.

## Frequently asked questions

### How do I convert binary to decimal?

Write the place values 128, 64, 32, 16, 8, 4, 2, 1 above the bits and add the values where the bit is 1. For 11001010 that is 128 + 64 + 8 + 2 = 202.

### How do I convert decimal to binary?

Divide by 2 repeatedly and write down the remainders. Read the remainders from last to first.

### Why does hexadecimal use letters?

Base 16 needs sixteen symbols. After 0 to 9, the letters A to F stand for 10 to 15.

### Why is one hex digit four bits?

Because 16 = 2⁴. Four bits can hold exactly 16 different values, which one hex digit represents.

### What does 0x mean?

In many programming languages, 0x in front of a number means it is written in hexadecimal, for example 0xFF is 255.

