Beginner · Subnetting practice and IPv6 · topic 16 of 57 · 35 min
Subnetting a network into equal subnets
Explanation
Why subnet at all?
Imagine an office with 600 PCs, printers, cameras and phones, all in one big network. Every broadcast (a message to everyone, such as an ARP request asking "who has this IP?" or a DHCP Discover) reaches all 600 devices. One misbehaving device can flood everyone. Accounts and the guest Wi-Fi sit side by side with nothing between them. And when something breaks, nobody knows where to look.
Subnetting splits that big network into smaller networks called subnets. Each subnet is its own broadcast domain: a broadcast stays inside it. A router (or a layer 3 switch) connects the subnets, and that is where you can put security rules. Subnets also give structure: one per floor, per department or per device type.
Borrowing bits
A network has a fixed number of host bits. To make subnets, you borrow some of those host bits and use them to number the subnets. The prefix gets longer by the number of borrowed bits. Start with 192.168.1.0/24: 8 host bits. Borrow 2 bits and the prefix becomes /26, with 6 host bits left.
- Number of subnets = 2^s, where s is the number of borrowed bits.
- Usable hosts per subnet = 2^h − 2, where h is the number of host bits left.
- s + h always equals the host bits you started with.
Worked example 1: 192.168.1.0/24 into 4 subnets
We need 4 subnets. 2^2 = 4, so borrow 2 bits. New prefix /24 + 2 = /26, mask 255.255.255.192. Host bits left 6, so 62 hosts each. Block size 256 − 192 = 64, so the subnets start at 0, 64, 128 and 192.
| Subnet | Network | Host range | Broadcast |
|---|---|---|---|
| 1 | 192.168.1.0/26 | .1 to .62 | 192.168.1.63 |
| 2 | 192.168.1.64/26 | .65 to .126 | 192.168.1.127 |
| 3 | 192.168.1.128/26 | .129 to .190 | 192.168.1.191 |
| 4 | 192.168.1.192/26 | .193 to .254 | 192.168.1.255 |
Worked example 2: the same /24 into 8 subnets
2^3 = 8, so borrow 3 bits. New prefix /27, mask 255.255.255.224, block size 32, hosts 2^5 − 2 = 30 each. The networks are 192.168.1.0, .32, .64, .96, .128, .160, .192 and .224, all /27. The last one runs from .224 to .255, with hosts .225 to .254.
Worked example 3: 172.16.0.0/16 into /20 subnets
Going from /16 to /20 borrows 4 bits, so there are 2^4 = 16 subnets. Host bits left 12, so 4,094 hosts each. The mask is 255.255.240.0 and the block of 16 is in the third octet. The subnets are 172.16.0.0/20, 172.16.16.0/20, 172.16.32.0/20 and so on up to 172.16.240.0/20. The first one runs from 172.16.0.1 to 172.16.15.254 (broadcast 172.16.15.255). The last one runs from 172.16.240.1 to 172.16.255.254 (broadcast 172.16.255.255).
Working from host counts
Often the question is not "how many subnets" but "each subnet needs H hosts". Find the smallest h where 2^h − 2 is at least H. For 50 hosts: 2^5 − 2 = 30 is too small, 2^6 − 2 = 62 is enough, so h = 6 and the prefix is 32 − 6 = /26.
import ipaddress
net = ipaddress.ip_network("192.168.1.0/24")
for subnet in net.subnets(new_prefix=26):
print(subnet, subnet.broadcast_address)Common mistakes
- Subtracting 2 from the number of subnets. Older textbooks did this because the first and last subnet ("subnet zero" and the all-ones subnet) were once avoided. Cisco IOS has allowed subnet zero by default since IOS 12.0, and the CCNA uses 2^s.
- Borrowing too many bits: always check that the subnets you get still hold enough hosts.
- Starting a subnet at a number that is not a multiple of the block size, such as 192.168.1.50/26. It is not a valid network address.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Subnetting a network into equal subnets · 1/8
Now we split one network into several smaller ones. This is subnetting, and it is the most practised skill for the CCNA.
Prefer a video by a teacher? Find free videos on “subnetting made easy ccna borrow bits example” on YouTube ↗
In real life: One /24 for a small CA office in Ahmedabad
A chartered accountancy firm has one /24, 192.168.50.0/24, and four groups: partners, staff, the file server and printers, and guest Wi-Fi. The IT vendor borrows 2 bits and creates four /26 subnets of 62 hosts each. Guests get 192.168.50.192/26 and a firewall rule stops that subnet from reaching the file server in 192.168.50.128/26. Client data stays away from visitors' phones, and broadcast noise from 40 guest phones never reaches the accounting PCs.
import ipaddress
names = ["partners", "staff", "servers", "guests"]
subnets = ipaddress.ip_network("192.168.50.0/24").subnets(new_prefix=26)
for name, subnet in zip(names, subnets):
print(name, subnet)Practice (0/4 done)
Write bits_for_subnets(n) that returns the smallest number of bits s to borrow so that 2 ** s is at least n. Example: bits_for_subnets(4) returns 2 and bits_for_subnets(5) returns 3.
Write prefix_for_hosts(hosts) that returns the longest prefix (the smallest subnet) that still has at least that many USABLE hosts. Find the smallest h with 2 ** h - 2 >= hosts, starting from h = 2, and return 32 - h. Example: prefix_for_hosts(50) returns 26.
Write split(network, new_prefix) that returns a list of all subnets (as strings) when you split network into subnets of new_prefix. Use ipaddress.ip_network(network).subnets(new_prefix=new_prefix).
You split 10.0.0.0/8 into /16 subnets. How many subnets do you get, and how many usable hosts does each have?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- VLSM: subnets of different sizesSubnetting practice and IPv6 · same module
- Subnetting drills for exam speedSubnetting practice and IPv6 · same module
- IPv6 addresses: format and shortening rulesSubnetting practice and IPv6 · same module
- IP addresses, subnets and CIDRCyber Security: from zero to SOC analyst · Networking for security
- VPC basics: CIDR, subnets and gatewaysCloud Computing (AWS, Azure, Google Cloud) · Networking and databases: VPC and RDS
- Binary and decimal for networkingIPv4 addressing
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
How many /28 subnets fit in a /24?
Answer: 16
From /24 to /28 borrows 4 bits: 2^4 = 16 subnets.
Each subnet must hold 25 hosts. Which prefix wastes the fewest addresses?
Answer: /27
/27 gives 30 usable hosts. /28 gives only 14, and /26 wastes more.
What is the third /26 subnet of 192.168.1.0/24?
Answer: 192.168.1.128/26
The /26 subnets start at 0, 64, 128 and 192, so the third is 192.168.1.128/26.
What is the main reason to split a large flat network into subnets?
Answer: To create smaller broadcast domains and allow security rules between groups
Each subnet is its own broadcast domain, and a router or layer 3 switch between subnets is where you apply rules.
What is the second /20 subnet of 172.16.0.0/16?
Answer: 172.16.16.0/20
A /20 has a block size of 16 in the third octet: 172.16.0.0, then 172.16.16.0.
What is the last usable host in 172.16.32.0/20?Related
Answer: 172.16.47.254
The block of 16 runs from 32 to 47 in the third octet. The broadcast is 172.16.47.255, so the last host is 172.16.47.254.
Where does Cisco IOS expect a wildcard mask instead of a subnet mask?Related
Answer: In access-list statements and the OSPF network command
Interfaces take subnet masks. ACLs and OSPF network statements take wildcard masks.
How many usable hosts are in a /28?Related
Answer: 14
2^(32−28) = 16 addresses, minus network and broadcast = 14.
Which of these is NOT a valid start for a /26 subnet?Related
Answer: 192.168.10.160
A /26 has a block size of 64, so it starts at 0, 64, 128 or 192. 160 is not a multiple of 64.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Subnetting practice and IPv6” before its exam: VLSM: subnets of different sizes, Subnetting drills for exam speed, IPv6 addresses: format and shortening rules, IPv6 address types, EUI-64, SLAAC and NDP.
- Module 4 exam: Subnetting practice and IPv6 · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Switching and VLANs. 57 topics left in the course before the final exam.
← Previous: Validating addresses and checking the same subnet