How Subnetting Works (CIDR, Masks and Host Counts)
A subnet is a block of IP addresses set by a prefix length such as /24. A /24 has 2^(32 − 24) = 256 addresses and 254 usable hosts. For 192.168.1.10/24, the network is 192.168.1.0, the broadcast is 192.168.1.255 and the mask is 255.255.255.0.
IP addresses are 32 bits
An IPv4 address such as 192.168.1.10 is four numbers (octets) of 8 bits each. The prefix length says how many of the first bits identify the network; the rest identify the host.
The subnet mask
A /24 means 24 ones then 8 zeros: 255.255.255.0. A /26 is 255.255.255.192. A /20 is 255.255.240.0.
Network and broadcast
The network address is the IP AND the mask (all host bits zero). The broadcast address has all host bits set to one. For 192.168.1.130/26, the network is 192.168.1.128 and the broadcast is 192.168.1.191.
Counting hosts
Addresses = 2^(32 − prefix) Usable hosts = addresses − 2| Prefix | Addresses | Usable hosts |
|---|---|---|
| /24 | 256 | 254 |
| /25 | 128 | 126 |
| /26 | 64 | 62 |
| /27 | 32 | 30 |
| /28 | 16 | 14 |
| /29 | 8 | 6 |
| /30 | 4 | 2 |
Splitting a network
Add 1 to the prefix to halve a network. A /24 splits into two /25 networks of 128 addresses each, then four /26 of 64, and so on. This is how you give each department or site its own subnet.
Private ranges
10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are reserved for private networks.
Special cases
A /31 links two devices and a /32 is a single host. Check your design with the IP subnet calculator, and estimate transfer speeds with the bandwidth calculator.
Key terms
- Prefix length: The number of network bits.
- Octet: One of the four 8-bit parts of an IPv4 address.
- Gateway: The router address that leads out of a subnet.
- VLSM: Using different prefix lengths in one network.
- Broadcast: An address that reaches every host in the subnet.
Practice questions
Try each one before you read the answer.
- How many usable hosts in a /27?
Answer: 30. - What is the mask for /28?
Answer: 255.255.255.240. - What subnet size do you need for 100 hosts?
Answer: /25 (126 usable hosts).
A worked subnetting example
You have 192.168.10.0/24 and need four subnets for four offices. Four subnets need 2 extra bits (2² = 4), so the new prefix is /26. Each subnet has 64 addresses and 62 usable hosts.
| Subnet | Network | Usable range | Broadcast |
|---|---|---|---|
| 1 | 192.168.10.0 | .1 to .62 | 192.168.10.63 |
| 2 | 192.168.10.64 | .65 to .126 | 192.168.10.127 |
| 3 | 192.168.10.128 | .129 to .190 | 192.168.10.191 |
| 4 | 192.168.10.192 | .193 to .254 | 192.168.10.255 |
Choosing the right size
Work out how many hosts you need, add some room to grow, and pick the smallest prefix that fits. For 50 hosts you need /26 (62 usable). For 100 hosts you need /25 (126). Do not make subnets much larger than needed, because it wastes addresses.
Common mistakes
- Giving a device the network or broadcast address.
- Overlapping subnets, which causes routing problems.
- Forgetting the router (gateway) takes one address.
Why subnet at all?
Splitting a network keeps traffic local, makes it easier to apply security rules between groups, limits how far a problem can spread and uses addresses efficiently. A home network is usually a single /24, while a company may have many subnets for staff, servers, guests and cameras.
Practise with small examples until splitting by powers of two feels natural.
Frequently asked questions
Why subtract 2 from the host count?
The first address is the network and the last is the broadcast, so neither can be given to a device.
What is CIDR notation?
An address followed by a slash and the prefix length, such as 10.0.0.0/8.
How many hosts are in a /30?
2 usable hosts, often used for links between two routers.