Fixed-size subnets waste addresses. Variable Length Subnet Masking gives each segment exactly the size it needs — the skill that separates real network design from theory.
Why: real networks have segments of wildly different sizes — 200 users here, a 2-address point-to-point link there — and cutting everything to one size either wastes thousands of addresses or leaves segments too small. When: use VLSM whenever address efficiency matters (which is always in production). Where: VLSM means applying different prefix lengths within the same parent network.
Requirement:
Sales 200 hosts Eng 60 hosts
Ops 25 hosts WAN link 2 hosts
Fixed /26 everywhere: each subnet = 62 hosts.
-> Sales (200) doesn't fit; the WAN link wastes 60 addresses.
VLSM: size each subnet to its need. Allocate LARGEST first.Why: VLSM works only if you assign the biggest subnets first from the top of the address space, then carve smaller ones from what remains — doing it out of order creates overlaps. When: sort requirements descending, pick the smallest prefix that fits each, and advance. Where: each subnet must round up to the next power of two (a segment needing 200 hosts takes a /24, not a /23-and-a-half).
Given 192.168.10.0/24, allocate largest-first:
Sales 200 hosts -> /24 needs 256... use a /24? Here assume /23 parent.
Sales 200 -> /24 (254 hosts) 192.168.10.0/24
Eng 60 -> /26 (62 hosts) 192.168.11.0/26
Ops 25 -> /27 (30 hosts) 192.168.11.64/27
WAN 2 -> /30 (2 hosts) 192.168.11.96/30
Smallest prefix that still fits the requirement. No gaps, no overlaps.Why: the fastest way to catch a VLSM mistake is to let code check that no two allocated subnets overlap — an overlap causes silent, hard-to-debug routing failures. When: validate every addressing plan before deploying it. Where: ipaddress makes overlap and containment checks one call each.
import ipaddress
plan = [
ipaddress.ip_network("192.168.11.0/26"), # Eng
ipaddress.ip_network("192.168.11.64/27"), # Ops
ipaddress.ip_network("192.168.11.96/30"), # WAN
]
for a, b in [(plan[i], plan[j]) for i in range(len(plan)) for j in range(i + 1, len(plan))]:
if a.overlaps(b):
print("OVERLAP:", a, b)
print("checked — no overlaps" )