# Subnetting for Beginners: Subnet Masks and CIDR Without the Headache

Subnetting is the topic where many beginners give up on networking. It looks like math, and it's usually taught with pages of binary. Here's the good news: for help desk work you need to understand what a subnet is and read a few common masks. For exams and interviews you need one counting trick. This post gives you both, one step at a time.

## What a subnet is

A **subnet** is a smaller network carved out of a bigger one. Companies split their networks into subnets to keep them organized and safer: one subnet for staff laptops, one for servers, one for printers, one for guest Wi-Fi.

Devices in the same subnet can talk to each other directly. To reach a device in a different subnet, traffic has to go through a router, the default gateway from [Post 7](https://adam2root.hashnode.dev/ip-addresses-explained). That's the part that matters every day: **if two devices aren't in the same subnet, they need a router between them.**

Security teams care about this too. If the guest Wi-Fi is a separate subnet with no route to the servers, a stranger on that Wi-Fi can't reach them. Splitting a network like this is called **segmentation**, and penetration testers check whether it really works.

## The two parts of an IP address

Every IP address has two parts:

- The **network part**, which says which subnet the device is in. It's the same for every device in that subnet.
- The **host part**, which identifies the device inside that subnet. It's different for every device.

The **subnet mask** tells you where one part ends and the other begins.

Take `192.168.1.23` with the mask `255.255.255.0`. A 255 in the mask means "this number is the network part". A 0 means "this number is the host part". So:

- Network part: `192.168.1`
- Host part: `23`

Every device whose address starts with `192.168.1.` is in the same subnet. `192.168.1.23` and `192.168.1.200` can talk directly. `192.168.2.5` is in a different subnet and needs the router.

## CIDR: the short way to write a mask

Writing `255.255.255.0` every time is long, so there's a shorter way called **CIDR notation**: a slash and a number, like `/24`.

The number says how many bits of the address are the network part. An IPv4 address has 32 bits, in four groups of 8 (from [Post 7](https://adam2root.hashnode.dev/ip-addresses-explained)). `255` means all 8 bits in that group are network bits. So:

- `255.255.255.0` is 8 + 8 + 8 = 24 network bits, so it's `/24`.
- `255.255.0.0` is 16 network bits, so it's `/16`.
- `255.0.0.0` is `/8`.

`192.168.1.23/24` means "the address 192.168.1.23, with the first 24 bits as the network part". It's the most common subnet you'll see, in almost every home and many offices.

## How many devices fit

The bits left over (32 minus the CIDR number) are for hosts. Each extra bit doubles the number of addresses. The formula is:

> addresses = 2 to the power of (32 − CIDR number)

Two addresses in every subnet are reserved and can't be given to a device:

- The **first** address is the **network address**, the name of the subnet itself (`192.168.1.0`).
- The **last** address is the **broadcast address**, used to send to every device in the subnet at once (`192.168.1.255`).

So usable addresses = total addresses − 2.

![Cheat sheet of common CIDR sizes, their subnet masks and how many devices fit](https://cdn.hashnode.com/uploads/covers/6afe08476920da9a67541ede/f6a2226e-90b0-412f-9b47-005226ce7aab.png align="center")

| CIDR | Subnet mask | Total addresses | Usable for devices |
| --- | --- | --- | --- |
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |

Notice the pattern: each step down the table halves the size. Once you know a `/24` has 256 addresses, you can work out the rest by halving.

## The counting trick: block size

When the mask isn't a simple 255 or 0, here's the method that works in your head. Use it for the last number of the mask.

1. **Find the block size:** 256 minus the last number of the mask. For `/26` (mask `255.255.255.192`), it's 256 − 192 = **64**.
2. **Count in blocks:** the subnets start at 0, 64, 128 and 192.
3. **Find where your address falls.** Each subnet runs from its start to one before the next start.

Example: which subnet is `192.168.1.100/26` in?

- Block size is 64, so the subnets are .0 to .63, .64 to .127, .128 to .191 and .192 to .255.
- 100 falls in **.64 to .127**.
- Network address: `192.168.1.64`. Broadcast address: `192.168.1.127`. Usable addresses: `.65` to `.126`.

Most beginner subnetting questions need only this method and the table above.

## How help desk uses this

You won't design subnets in a first IT job, but you'll read them all the time:

- A laptop shows `192.168.5.40` and the printer is `192.168.6.12`. They're in different subnets, so the laptop reaches the printer through the router. If the router or a firewall blocks that path, printing fails.
- Someone set a static address by hand with the wrong mask. The computer now thinks devices it should reach directly are "outside", or the other way round. Checking the mask in `ipconfig` catches it.
- A company's IT documentation says "servers are on 10.10.20.0/24". Now you know that means 10.10.20.1 to 10.10.20.254.

## Your exercise

Answer these on paper first, then check with a [subnet calculator](https://www.calculator.net/ip-subnet-calculator.html). The answers are at the bottom.

1. What is `/16` written as a subnet mask?
2. How many usable addresses does a `/28` have?
3. Are `10.0.5.20/24` and `10.0.6.20/24` in the same subnet?
4. Which subnet is `192.168.10.77/27` in? Give the network and broadcast addresses.
5. Run `ipconfig` on your computer. What is your subnet mask, and what is it in CIDR notation? How many devices could your home network hold?

Then do ten questions on [Subnetting Practice](https://subnettingpractice.com/), a free site that generates new questions each time. Repeat a few days later. That's what makes it stick.

**Answers:** 1. `255.255.0.0`. 2. 14 (16 − 2). 3. No, the third number is different, and with `/24` the first three numbers are the network part. 4. Block size is 256 − 224 = 32, so subnets start at 0, 32, 64, 96. 77 is in the one that starts at 64: network `192.168.10.64`, broadcast `192.168.10.95`. 5. Most homes show `255.255.255.0`, which is `/24`, so 254 devices.

## Keep learning

- [**Professor Messer's Network+ course**](https://www.professormesser.com/network-plus/n10-009/n10-009-video/n10-009-training-course/)**.** Has free videos on IPv4 subnetting that go further than this post, including the binary.
- [**Cloudflare: What is a subnet?**](https://www.cloudflare.com/learning/network-layer/what-is-a-subnet/) A short written explanation of why networks are split up.

## What's next

[The next post](https://adam2root.hashnode.dev/routers-switches-wifi-osi-model) finishes the networking theory: routers, switches, Wi-Fi, and the layered models (OSI and TCP/IP) that networking people use to describe where a problem is.

Which of the five questions was the hardest for you? Tell me in the comments.

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