Subnets: masks and splitting a network
Lesson 1 of 6
1Subnets: masks and splitting a network
The big pictureA building has 256 flats. You can make it one big block, or split it into four floors of 64, so each floor's noise stays on that floor and it is easier to manage. Subnetting is exactly that, and the prefix says where the floor number ends and the flat number starts.
What the picture shows: Four steps solve any subnet question: write the prefix, split the bits, work out the block size, then read off the network's edges.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Floors and flats: the prefix /24 means the first 24 bits are the "floor number" and the last 8 the "flat number", so a floor has 256 numbers. Make it /26 and the floor number grows, giving four smaller floors of 64. The first number of each floor is the floor's own name, the last is a loudspeaker calling everyone, and the rest are for devices.
A /n prefix means n network bits and 32 − n host bits. The mask is the prefix in dotted form (/26 = 255.255.255.192). Block size is 2^(32−n) and hosts 2^h − 2 (except /31 for point-to-point links per RFC 3021 and /32 for one address). Network = address AND mask; broadcast = network OR wildcard. VLSM splits into different sizes, largest first.
Before You Start
🏷️Addresses
You know IPv4 is four 8-bit octets.
🔢Powers of two
2, 4, 8, 16, 32, 64, 128, 256.
The Core Idea
1Try it before you calculate it
Move the prefix slowly from /24 to /30. Each step moves one bit from hosts to network, halving the number of addresses.
Subnet calculator
Type an address and move the prefix. Green bits are the network part, orange bits the host part. Try /24, then /26, then /30 and watch the host count.
Network partHost part
Not a valid address: write four numbers from 0 to 255 separated by dots, like 10.0.5.1
- Network
- 192.168.10.64/26
- Mask
- 255.255.255.192
- Wildcard
- 0.0.0.63
- First host
- 192.168.10.65
- Last host
- 192.168.10.126
- Broadcast
- 192.168.10.127
- Usable hosts
- 62
2The mask and the block size
In the octet where the prefix falls, the mask can only be a few values: 128, 192, 224, 240, 248, 252, 254, 255. Memorise this ladder and you will solve most questions in your head. Block size = 256 − the mask number, and subnets start at its multiples.
3A network's edges: network, broadcast, hosts
Take 192.168.10.77/26. The block is 64, the multiples 0, 64, 128, 192. 77 sits between 64 and 127, so the network is 192.168.10.64, the broadcast 192.168.10.127, and hosts run .65 to .126: 62 devices.
Python checks your hand calculation. Change the address or the prefix.
import ipaddress
iface = ipaddress.ip_interface("192.168.10.77/26")
net = iface.network
hosts = list(net.hosts())
print("network: ", net.network_address)
print("broadcast:", net.broadcast_address)
print("mask: ", net.netmask)
print("hosts: ", hosts[0], "to", hosts[-1], f"({len(hosts)})")/24 has 256 addresses but only 254 devices, because the first names the network and the last is the broadcast.4Splitting into different sizes (VLSM)
Companies do not need equal parts. One department has 100 devices, another 50, and a link between two routers needs only two addresses. The method: sort largest to smallest, give each the smallest block that fits, and start each block where the last ended.
That is all of VLSM in ten lines. Add a department and run.
import ipaddress
import math
space = ipaddress.ip_network("10.10.0.0/24")
needs = {"Sales": 100, "Support": 50, "Guests": 20, "R1-R2 link": 2}
start = space.network_address
for name, hosts in sorted(needs.items(), key=lambda item: -item[1]):
size = 2 ** math.ceil(math.log2(hosts + 2)) # + network and broadcast
prefix = 32 - int(math.log2(size))
subnet = ipaddress.ip_network(f"{start}/{prefix}")
print(f"{name:<11} needs {hosts:>3} -> {subnet} ({size - 2} usable)")
start = subnet.broadcast_address + 1Worked example
The task: split 172.16.0.0/22 into 8 equal subnets (an exercise from your guide's plan). The answer: 8 = 2³, so borrow 3 bits: /22 + 3 = /25. Each subnet is 2^7 = 128 addresses, 126 hosts. The subnets: 172.16.0.0/25, 172.16.0.128/25, 172.16.1.0/25, 172.16.1.128/25, 172.16.2.0/25, 172.16.2.128/25, 172.16.3.0/25, 172.16.3.128/25.
The check: the same eight subnets.
import ipaddress
for subnet in ipaddress.ip_network("172.16.0.0/22").subnets(prefixlen_diff=3):
print(subnet, "-", subnet.num_addresses - 2, "hosts")/24 question in under two minutes with no tools.Myth vs Reality
| Myth | Reality |
|---|---|
| The mask and the prefix are different things. | They are the same thing written two ways: /26 = 255.255.255.192. |
| A bigger network is always better. | Every device hears everyone's broadcast; a huge network is slower and harder to isolate and secure. |
| IPv6 needs no subnetting. | It does, but more simply: a local network is almost always a /64. |
Where you meet it at work
🏢Designing a company network
Each department or floor gets a subnet and a VLAN, with guests isolated.
☁️The cloud
Creating a VPC starts with choosing a range like 10.0.0.0/16 and splitting it.
🎓Certificates
Subnet questions on Network+ and CCNA come without a calculator.
Test your understanding
How many hosts in a /27?
5 host bits: 2⁵ = 32, minus 2 = 30.
What is the mask for /28?
Four network bits in the last octet: 128+64+32+16 = 240.
What is the broadcast of the subnet holding 10.0.0.70/26?
The block is 64; 70 falls in 64 to 127.
You need 4 equal subnets from a /24. What is the new prefix?
4 = 2², so borrow two bits: 24 + 2 = 26.
How many usable host addresses in a /27?
2^5 = 32, minus network and broadcast = 30.
What is the /26 mask in dotted decimal?
The last octet is 11000000 = 192, a block size of 64.
Quick review cards
Check Your Understanding
Why is a /30 enough for a link between two routers?
It has 4 addresses: network, broadcast and two for the routers. A /31 works too, since a point-to-point link needs no broadcast.
What is the wildcard for /24, and where do you see it?
0.0.0.255, seen in ACLs and OSPF configuration on Cisco devices.
Are 192.168.1.64/26 and 192.168.1.100/26 on the same subnet?
Yes, both fall between 64 and 127.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Official docs1
Done with this lesson?
Sign in to save your progress.