# Binary for Beginners: How Computers Count (and Why IT Cares)

Everything a computer stores, from a photo to a password to this sentence, ends up as a long row of 0s and 1s. That's binary. You don't need to read binary all day to work in IT, but you do need to understand how it counts, because it explains things you'll meet constantly: why an IP address stops at 255, what a subnet mask really is, why a "1 TB" drive shows up as 931 GB, and why hackers' tools are full of numbers that look like gibberish. This post teaches you to convert numbers by hand, then gives you calculators and games so the skill sticks.

## Bits and bytes

A computer is built from billions of tiny switches. Each switch is either off or on. We write off as **0** and on as **1**. One of these 0-or-1 values is called a **bit** (short for binary digit).

One bit can only say two things. Put bits together and you get more:

- 1 bit: 2 possible values (0, 1)
- 2 bits: 4 values (00, 01, 10, 11)
- 8 bits: 256 values

A group of **8 bits** is a **byte**. One byte can hold any number from 0 to 255. Remember that range: you'll see it again in a minute.

Bigger units are built from bytes: a kilobyte (KB), megabyte (MB), gigabyte (GB) and terabyte (TB). Drive makers count these in thousands: 1 TB = 1,000,000,000,000 bytes. Windows counts in steps of 1,024 but still calls them GB. That's why a new 1 TB drive shows up in Windows as about 931 GB. Nothing is missing. It's the same number of bytes, counted two ways, and it's a classic help desk question.

## Counting in base 10 vs base 2

You already know one number system: decimal, or **base 10**. It has ten digits (0 to 9), and each position is worth ten times the one to its right. In 365, the 3 means 3 hundreds, the 6 means 6 tens and the 5 means 5 ones.

Binary, or **base 2**, works the same way with only two digits (0 and 1). Each position is worth **two times** the one to its right. For one byte, the eight positions are worth:

| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| --- | --- | --- | --- | --- | --- | --- | --- |

You don't need to memorize this row. Start with 1 on the right and keep doubling to the left: 1, 2, 4, 8, 16, 32, 64, 128.

## Binary to decimal

To read a binary number, write it under the place values. Every position with a 1 counts, every 0 doesn't. Add up the ones that count.

![Binary place values: 11001000 is 128 + 64 + 8 = 200, and 00001010 is 8 + 2 = 10](https://cdn.hashnode.com/uploads/gql/6afe08476920da9a67541ede/90e017ca-3cb5-4ac0-91c1-86467678b8d8.png align="center")

Take `11001000`:

- 1 under 128: counts
- 1 under 64: counts
- 0 under 32, 0 under 16: skip
- 1 under 8: counts
- 0 under 4, 2 and 1: skip

128 + 64 + 8 = **200**.

A few patterns that make it faster:

- `11111111` is 255, the biggest number in one byte (128+64+32+16+8+4+2+1).
- `00000000` is 0.
- Leading zeros don't change the value: `00001010` and `1010` are both 10. In networking we usually write all eight bits anyway.
- If the last bit is 0, the number is even. If it's 1, the number is odd.

## Decimal to binary

To go the other way, use subtraction. Walk the place values from left to right. If the place value fits into what's left of your number, write 1 and subtract it. If it doesn't fit, write 0 and move on.

Convert **200**:

| Place value | Does it fit? | Bit | Left over |
| --- | --- | --- | --- |
| 128 | 200 ≥ 128, yes | 1 | 200 − 128 = 72 |
| 64 | 72 ≥ 64, yes | 1 | 72 − 64 = 8 |
| 32 | 8 &lt; 32, no | 0 | 8 |
| 16 | 8 &lt; 16, no | 0 | 8 |
| 8 | 8 ≥ 8, yes | 1 | 8 − 8 = 0 |
| 4 | no | 0 | 0 |
| 2 | no | 0 | 0 |
| 1 | no | 0 | 0 |

Read the Bit column from top to bottom: **11001000**. Check it by converting back: 128 + 64 + 8 = 200.

Try one in your head: **10**. 128, 64, 32 and 16 don't fit (0000). 8 fits, 2 left (1). 4 doesn't fit (0). 2 fits, 0 left (1). 1 doesn't fit (0). Result: `00001010`.

## Where you'll see binary in IT

### IP addresses

An IPv4 address like `192.168.1.10` (from [Post 7](https://adam2root.hashnode.dev/ip-addresses-explained)) is really 32 bits. The dots split it into four bytes, called **octets**, and each one is written in decimal so humans can read it.

![The IP address 192.168.1.10 in binary: 11000000, 10101000, 00000001 and 00001010, four octets of 8 bits each](https://cdn.hashnode.com/uploads/gql/6afe08476920da9a67541ede/79f23c95-6b8a-4c5e-a28f-6aefd7663066.png align="center")

That's why no part of an IP address can be higher than 255: each part is one byte. It's also why there are about 4.3 billion IPv4 addresses in total: 32 bits give 2³² = 4,294,967,296 combinations.

### Subnet masks

In [Post 10](https://adam2root.hashnode.dev/subnetting-for-beginners) you met masks like `255.255.255.0` and the shorthand `/24`. Here's what's underneath:

```plaintext
255.255.255.0  =  11111111.11111111.11111111.00000000
```

Count the 1s: 24. That's all `/24` means: the first 24 bits are the network part, and the rest are for devices. A `/26` mask has 26 ones:

```plaintext
255.255.255.192  =  11111111.11111111.11111111.11000000
```

`11000000` is 128 + 64 = 192. The block-size trick from Post 10 (256 − 192 = 64 addresses per subnet) now makes sense: the remaining six 0 bits can count from 0 to 63, which is 64 addresses.

### And later in the course

You'll meet binary again in Linux file permissions (`chmod 755` is three groups of three bits), in hexadecimal (the next post), and in hacking tools that show the raw bytes of files and network traffic.

## Tools that do it for you

Converting by hand teaches you how it works. In real work, you use a calculator. Here are three.

**Windows Calculator, Programmer mode.** Open Calculator, click the menu (the three lines at the top left) and choose **Programmer**. Type a number and you see it in four systems at once: HEX (hexadecimal), DEC (decimal), OCT (octal) and BIN (binary). Click **BIN** to type in binary instead. It's built into every Windows PC, so it's the one you'll use at work.

**PowerShell.** Two one-line commands:

```powershell
[Convert]::ToString(200, 2)
```

Output: `11001000`. `[Convert]` is a built-in .NET helper, `ToString` turns a number into text, and the `2` means "in base 2".

```powershell
[Convert]::ToInt32("11001000", 2)
```

Output: `200`. `ToInt32` turns text into a whole number, and the `2` says the text is in base 2.

**Online converters.** RapidTables has a [decimal to binary converter](https://www.rapidtables.com/convert/number/decimal-to-binary.html) and a [binary to decimal converter](https://www.rapidtables.com/convert/number/binary-to-decimal.html) that show the working, step by step. Useful for checking your answers.

## Practice with games

Binary gets easy with repetition, and games are the least boring way to repeat it.

![The start screen of the Cisco Binary Game, with the place values 128 to 1 across the top](https://cdn.hashnode.com/uploads/gql/6afe08476920da9a67541ede/553aa20a-b1e1-4dec-bdb3-aa14393ba49e.png align="center")

- [**Cisco Binary Game**](https://learningcontent.cisco.com/games/binary/index.html)**.** Free, in the browser. Rows fall down the screen like Tetris. For each row, either flip the bits to match the decimal number, or type the decimal number that matches the bits. The place values sit at the top and bottom, so you can't get lost. Aim to clear level 3.
- [**Penjee Binary Numbers Game**](https://games.penjee.com/binary-numbers-game/)**.** A free remake of the same idea, if the Cisco one doesn't load for you.
- [**CS Unplugged: Binary Numbers**](https://www.csunplugged.org/en/topics/binary-numbers/)**.** Free activities that teach binary with dot cards you can draw on paper. Good if you learn better away from the screen.

## What to remember for now

You don't need to convert binary at speed, and nobody at a help desk will test you on it. What matters right now:

- A **bit** is a 0 or 1. A **byte** is 8 bits and holds 0 to 255.
- The place values **128, 64, 32, 16, 8, 4, 2, 1**, which you can rebuild any time by doubling from 1.
- How to convert one byte both ways with the method above.
- An IP address is four bytes, and `/24` means 24 ones in the mask.

Speed comes with practice. Play the game for ten minutes a few times this week and it'll feel natural.

## Your exercise

1. From memory, write the eight place values of a byte. Check them against the table.
2. Convert to binary by hand: **13**, **100**, **172**, **255**, **192**. Then check each one in Windows Calculator's Programmer mode.
3. Convert to decimal by hand: `01010101`, `11110000`, `00100000`.
4. Run `ipconfig` in Command Prompt, find your IPv4 address, and write all four octets in binary.
5. What is the subnet mask `/26` in normal dotted decimal? (Hint: write 26 ones, then 0s up to 32 bits.)
6. Play the [Cisco Binary Game](https://learningcontent.cisco.com/games/binary/index.html) until you clear level 3. Then come back in two days and play it again.

**Answers:** 13 = `00001101`, 100 = `01100100`, 172 = `10101100`, 255 = `11111111`, 192 = `11000000`. `01010101` = 85, `11110000` = 240, `00100000` = 32. `/26` = `255.255.255.192`.

## Keep learning

- [**Khan Academy: Bits and binary**](https://www.khanacademy.org/computing/computers-and-internet/xcae6f4a7ff015e7d:digital-information/xcae6f4a7ff015e7d:binary-numbers/a/bits-and-binary)**.** A free, short lesson with practice questions.
- [**Math is Fun: Binary number system**](https://www.mathsisfun.com/binary-number-system.html)**.** A simple explanation with pictures, good for a second angle.

## What's next

Binary is great for computers and terrible for humans: 32 bits is a lot of 0s and 1s to read. The next post covers hexadecimal, the shorthand IT uses instead. You'll learn to read it, convert it, and spot it in MAC addresses, error codes and colors.

How far did you get in the Cisco Binary Game? Tell me in the comments.

If you want to follow along, connect with me on [LinkedIn](https://www.linkedin.com/in/adammichalsiman/).
