Subnetting and CIDR
Split one block of addresses into right-sized subnets: the powers-of-two method, host counts, block sizes, and worked examples you can repeat by hand.
Why subnet?
A single large network has problems: every broadcast reaches every host, you cannot apply different security rules to different groups, and one fault affects everyone. Subnetting divides an address block into smaller networks, each its own broadcast domain, connected by a router or layer 3 switch. Typical splits are by department (staff, guests, servers) or by function (voice, printers, cameras).
Subnetting is also a skill that is easy to learn and easy to forget without practice. Learn the method once, then practise.
CIDR notation
The prefix length (the number after the slash) says how many of the 32 bits are the network part. In the early internet, networks came in fixed “classes” (A, B and C, with 8, 16 and 24 network bits). That wasted huge numbers of addresses: a company needing 1,000 addresses had to take a 65,534-address class B.
CIDR (Classless Inter-Domain Routing) removed the classes. Any prefix length from /0 to /32 is allowed, so you can allocate precisely what you need. It also lets many contiguous blocks be summarised into one routing-table entry.
The key numbers
For a prefix of length n:
- Host bits = 32 - n
- Total addresses = 2^(host bits)
- Usable hosts = total - 2 (network address and broadcast address), for normal subnets
- Block size (in the interesting octet) = 256 - the mask’s value in that octet
Memorise the powers of two: 1, 2, 4, 8, 16, 32, 64, 128, 256.
| Prefix | Mask | Total addresses | Usable hosts |
|---|---|---|---|
| /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 |
Worked example 1: find the subnet of a host
Question: Which subnet does 192.168.10.200/26 belong to? What are its network address, broadcast address and usable range?
- A /26 uses the first 26 bits. The mask is
255.255.255.192. - The interesting octet is the fourth. Block size = 256 - 192 = 64.
- Subnets in that octet start at multiples of 64: 0, 64, 128, 192.
- 200 falls in the block starting at 192.
- Network
192.168.10.192, broadcast192.168.10.255(next block start 256, minus 1), usable192.168.10.193to192.168.10.254(62 hosts).
Worked example 2: carve a block into equal subnets
Question: Divide 10.20.0.0/24 into four equal subnets.
Four subnets need 2 extra bits (2^2 = 4), so the new prefix is /24 + 2 = /26. Block size is 64:
| Subnet | Network | Usable range | Broadcast |
|---|---|---|---|
| 1 | 10.20.0.0/26 | .1 to .62 | .63 |
| 2 | 10.20.0.64/26 | .65 to .126 | .127 |
| 3 | 10.20.0.128/26 | .129 to .190 | .191 |
| 4 | 10.20.0.192/26 | .193 to .254 | .255 |
Worked example 3: when the boundary is not in the last octet
Question: What are the network and broadcast addresses of 172.16.77.9/20?
- /20 means 20 network bits: the first two octets (16 bits) plus 4 bits of the third octet. The third octet of the mask is
11110000= 240. - Block size in the third octet = 256 - 240 = 16.
- Multiples of 16: 0, 16, 32, 48, 64, 80. 77 lies between 64 and 79, so the block starts at 64.
- Network
172.16.64.0/20, broadcast172.16.79.255, usable172.16.64.1to172.16.79.254(4,094 hosts).
Sizing subnets to need: VLSM
Equal subnets are not always efficient. Variable-length subnet masking (VLSM) lets you use different prefix lengths from the same block. The method:
- List the subnets you need and their host counts.
- Sort largest first.
- Allocate each from the block, using the smallest prefix that fits (usable hosts must be at least the number needed, and plan for growth).
- Place each at the next free boundary so subnets never overlap.
Example, from 192.168.5.0/24: Staff 100 hosts, Guests 50, Servers 20, a router link 2.
- Staff: needs 100 → /25 (126 usable) →
192.168.5.0/25 - Guests: needs 50 → /26 (62) →
192.168.5.128/26 - Servers: needs 20 → /27 (30) →
192.168.5.192/27 - Link: needs 2 → /30 (2) →
192.168.5.224/30
Everything fits and 192.168.5.228 onwards is free for growth. Document it: a subnet plan nobody wrote down becomes a mystery within a year.
Check your answers with a tool
Online calculators are fine for checking, but build the skill first. A few lines of Python can verify any answer:
import ipaddress
n = ipaddress.ip_network("172.16.77.9/20", strict=False)
print(n.network_address, n.broadcast_address, n.num_addresses - 2)
The lab at the end of this course asks you to write this calculator yourself.
Divide 192.168.100.0/24 into subnets that can each hold at least 25 hosts. What prefix do you use, how many subnets do you get, and what are the first two networks?
25 hosts need 5 host bits (2^5 = 32 addresses, 30 usable), so the prefix is /27. 8 bits - 5 host bits = 3 subnet bits, giving 8 subnets. The first two are 192.168.100.0/27 and 192.168.100.32/27.
Can You Explain It?
Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.
- Explain, without a calculator, how you find the network address of 10.1.99.130/21.
- Why do we subtract two from the number of addresses to count usable hosts, and when is that not true?
- What is the advantage of VLSM over splitting a block into equal subnets?
🧪 Want to practise this on your own computer? See how to set up your lab →