Beginner · Subnetting practice and IPv6 · topic 17 of 57 · 35 min
VLSM: subnets of different sizes
Explanation
Why equal subnets waste addresses
With equal subnets, every subnet has the size of the biggest one. If your largest group needs 100 hosts, every subnet becomes a /25 with 126 hosts. A link between two routers needs only 2 addresses, so a /25 on that link wastes 124. A /24 holds only two /25s, so you run out after two groups.
VLSM, Variable Length Subnet Masking, means using different prefix lengths inside the same block. Big groups get big subnets, small groups get small ones. All modern routing protocols (OSPF, EIGRP, BGP, RIP version 2) send the mask with each route, so VLSM works everywhere today.
The largest-first method
- List every group and how many hosts it needs. Count the router's gateway address as a host, and add room to grow.
- Sort the list from the largest to the smallest.
- For each group, pick the smallest prefix where 2^h − 2 is at least the host count.
- Give the first group the start of the block. Give each next group the address right after the previous broadcast address.
- Write down network, mask, host range and broadcast for each, and keep the leftover space as one or more free blocks.
Why largest first? A subnet must start at a multiple of its own block size: a /26 starts at 0, 64, 128 or 192. If you go from largest to smallest, the next free address is always a multiple of the next block size, so the subnets line up with no gaps and no overlap.
A full worked plan: an engineering college in Pune
The college has 192.168.10.0/24 for its new academic block. It needs: computer labs 100 hosts, staff 50 hosts, administration 25 hosts, and two point-to-point links to other buildings, 2 hosts each.
- Labs, 100 hosts: 2^7 − 2 = 126 is enough, so /25. Start at the beginning: 192.168.10.0/25, hosts .1 to .126, broadcast .127.
- Staff, 50 hosts: 2^6 − 2 = 62, so /26. Next free address is .128: 192.168.10.128/26, hosts .129 to .190, broadcast .191.
- Admin, 25 hosts: 2^5 − 2 = 30, so /27. Next free is .192: 192.168.10.192/27, hosts .193 to .222, broadcast .223.
- Link 1, 2 hosts: /30. Next free is .224: 192.168.10.224/30, hosts .225 and .226, broadcast .227.
- Link 2, 2 hosts: /30. Next free is .228: 192.168.10.228/30, hosts .229 and .230, broadcast .231.
| Group | Hosts needed | Prefix (usable) | Network | Host range | Broadcast |
|---|---|---|---|---|---|
| Labs | 100 | /25 (126) | 192.168.10.0 | .1 to .126 | .127 |
| Staff | 50 | /26 (62) | 192.168.10.128 | .129 to .190 | .191 |
| Admin | 25 | /27 (30) | 192.168.10.192 | .193 to .222 | .223 |
| Link 1 | 2 | /30 (2) | 192.168.10.224 | .225 to .226 | .227 |
| Link 2 | 2 | /30 (2) | 192.168.10.228 | .229 to .230 | .231 |
| Free | later use | /29 and /28 | 192.168.10.232/29, 192.168.10.240/28 |
Everything fits in one /24 with 24 addresses to spare. With equal /25 subnets, the same needs would not have fitted at all.
import ipaddress
plan = ["192.168.10.0/25", "192.168.10.128/26", "192.168.10.192/27", "192.168.10.224/30", "192.168.10.228/30"]
nets = [ipaddress.ip_network(p) for p in plan]
for a in nets:
for b in nets:
if a != b and a.overlaps(b):
print("overlap:", a, b)
print("checked", len(nets), "subnets")Common mistakes
- Starting a subnet on a wrong boundary, such as 192.168.10.200/26. A /26 must start at 0, 64, 128 or 192.
- Forgetting the gateway: a group of 30 PCs plus the router needs 31 addresses, so a /27 (30) is too small.
- No room to grow: the lab with 100 PCs may have 130 next year. Leave spare space where you can.
- Going smallest first, which leaves gaps and breaks the alignment of later, bigger subnets.
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
VLSM: subnets of different sizes · 1/7
Equal subnets waste addresses, because every subnet gets the size of the biggest one. VLSM fixes this.
Prefer a video by a teacher? Find free videos on “vlsm subnetting step by step example ccna” on YouTube ↗
In real life: A hospital chain adds a new branch
A hospital chain in Hyderabad gives each new branch a 10.40.x.0/24 from its master plan. The network engineer for the Kukatpally branch has wards (90 devices), OPD and pharmacy (40), doctors' offices (20), CCTV (12) and one WAN link. Largest first, she gets a /25, a /26, a /27, a /28 and a /30, all inside the branch /24, with space left for the medical devices that are coming next year. She uses a small script to print the plan and pastes it into the change request.
import ipaddress
needs = [("wards", 25), ("opd", 26), ("doctors", 27), ("cctv", 28), ("wan", 30)]
start = ipaddress.ip_address("10.40.7.0")
for name, prefix in needs:
net = ipaddress.ip_network(f"{start}/{prefix}")
print(name, net)
start = net.broadcast_address + 1Practice (0/3 done)
Write fits(hosts, prefix) that returns True when a subnet with that prefix has enough USABLE addresses for the hosts (2 ** (32 - prefix) - 2 >= hosts).
Build a VLSM allocator. vlsm(base, host_counts) sorts the host counts from largest to smallest, gives each the smallest subnet that fits (prefix_for is written for you), allocates them one after another from the start of base, and returns the list of subnets as strings in that order. If a subnet would go outside base, raise ValueError. Tip: ipaddress.ip_network((number, prefix)) builds a network from an integer address and a prefix, and net.subnet_of(base_net) tells you if it is inside.
Design a VLSM plan for a hospital branch in Lucknow that has 10.20.0.0/22. Needs: wards 300 hosts, OPD 120, labs 60, admin 28, and two router links of 2 hosts each. For each group give the network with prefix, the mask, the host range and the broadcast. List the free space left over.
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
- Subnetting drills for exam speedSubnetting practice and IPv6 · same module
- IPv6 addresses: format and shortening rulesSubnetting practice and IPv6 · same module
- Network, broadcast and usable host rangeIPv4 addressing
- 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
- Access control lists (ACLs)Network security
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.
In VLSM, why do you allocate the largest subnet first?
Answer: It keeps each subnet on a valid boundary with no gaps or overlaps
Going largest first means the next free address is always a multiple of the next, smaller block size.
Which prefix should a link between two routers get in a classic CCNA VLSM plan?
Answer: /30
A /30 has exactly 2 usable addresses, one for each router. (/31 is also possible under RFC 3021.)
A group has 30 PCs plus the router gateway. Which is the smallest prefix that fits?
Answer: /26
31 addresses are needed. A /27 has only 30 usable, so you need a /26 (62).
Which of these is NOT a valid start for a /26 subnet?
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.
After 192.168.10.0/25 and 192.168.10.128/26 are used, where does the next subnet start?
Answer: 192.168.10.192
The /26 ends at broadcast 192.168.10.191, so the next free address is 192.168.10.192.
Each subnet must hold 25 hosts. Which prefix wastes the fewest addresses?Related
Answer: /27
/27 gives 30 usable hosts. /28 gives only 14, and /26 wastes more.
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.
Are 10.1.1.100/25 and 10.1.1.130/25 in the same subnet?Related
Answer: No
/25 splits the octet at 128. 100 is in 0 to 127, 130 is in 128 to 255, so they are in different subnets.
Is 192.168.0.255/23 a usable host address?Related
Answer: Yes, the subnet runs from 192.168.0.0 to 192.168.1.255
In a /23 the broadcast is 192.168.1.255. 192.168.0.255 is in the middle of the range, so it is a normal host.
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
- 3 more topics in “Subnetting practice and IPv6” before its exam: 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.