VLSM & address planning
Design a variable-length subnet plan that fits each segment's host count with no overlaps.
By Invicly Tech, , in Computer Networking. About 9 minutes to read.
In short
Variable-length subnet masking lets each subnet be just big enough for its hosts instead of making every subnet the same size. You allocate the largest subnets first, aligned on their block size, then fill the gaps with smaller ones. Contiguous allocations can later be summarised into a single route.
Explained simply
If every subnet had the same size, you would waste lots of addresses. A link between two routers needs 2 addresses, but a staff floor might need 300. Giving both a /23 would throw away hundreds of addresses on the link.
VLSM (variable-length subnet masking) means using different prefix lengths inside one block of addresses. Each subnet gets the smallest size that fits its hosts, plus some room to grow.
The method is like packing a suitcase: big items first. Sort your subnets from largest to smallest, give the largest one the first block, then place each next one right after the previous. Because every subnet must start on a multiple of its own size, packing big first leaves no awkward gaps.
A good plan also makes routing simpler. If all the subnets of one site sit inside one bigger block, other routers can reach the whole site with a single route, called a summary route. A messy plan needs many routes and is harder to secure.
Press Play on a diagram to walk through it one step at a time.
- Staff: 100 hosts
- 192.168.1.0/25
- Guests: 50 hosts
- 192.168.1.128/26
- Servers: 20 hosts
- 192.168.1.192/27
- Printers: 10 hosts
- 192.168.1.224/28
- Router links
- 192.168.1.240/30
- 192.168.1.244/30
- 6 segments x 512 = 3,072 addresses
- Needs a /20 to hold them
- Router links waste 510 each
- Simple but wasteful
- /23 + /25 + /26 + /27 + 2 x /30
- Fits inside one /22
- Links use 4 addresses each
- Room left to grow
In depth
Sizing each subnet
For each segment, take the number of hosts you need now, add growth (often 25 to 50 percent), and remember the gateway counts as a host too. Then find the smallest power of two that is at least hosts + 2. For 300 hosts, 512 is the next power of two, so a /23 (510 usable). For 120 hosts, 128 is enough: /25 (126 usable). For 25 hosts: /27 (30 usable).
Watch the edges. 62 hosts fit a /26 exactly, but 63 do not, and that one extra device forces you to double the subnet. If a segment is right at the limit, choose the next size now; renumbering a live subnet later means changing every static address, DHCP scope, firewall rule and DNS record that mentions it.
- Needed block = smallest 2^h with 2^h - 2 at least hosts
- 300 hosts: /23, 120: /25, 60: /26, 25: /27, 10: /28
- Count the gateway, printers and future devices
- Point-to-point links: /30 or /31
Allocating largest first, on aligned boundaries
A subnet must start on a multiple of its block size. A /26 can start at .0, .64, .128 or .192, never at .32. If you place a small /27 at .0 first, the next /25 cannot start at .32; it must jump to .128, leaving a gap from .32 to .127 that only small subnets can fill.
Placing the largest first avoids that. Take 10.20.0.0/22 with needs of 300, 120, 60 and 25 hosts plus two router links. The 300-host /23 takes 10.20.0.0 to 10.20.1.255. The 120-host /25 takes 10.20.2.0. The 60-host /26 takes 10.20.2.128. The 25-host /27 takes 10.20.2.192. Two /30 links take 10.20.2.224 and 10.20.2.228. Everything from 10.20.2.232 to 10.20.3.255 stays free and contiguous for growth.
- 1300 hosts: /23
10.20.0.0 to 10.20.1.255
- 2120 hosts: /25
10.20.2.0 to 10.20.2.127
- 360 hosts: /26
10.20.2.128 to 10.20.2.191
- 425 hosts: /27
10.20.2.192 to 10.20.2.223
- 52 links: /30 each
10.20.2.224 and 10.20.2.228
- 6Free
10.20.2.232 to 10.20.3.255
/30 versus /31 for router links
A link between two routers needs exactly two addresses. A /30 gives 4 addresses: network, two usable and broadcast, so half are wasted. RFC 3021 allows /31 on point-to-point links: both addresses are usable because a link with two ends needs no broadcast. Cisco IOS, Juniper and Linux all support it, and large networks with thousands of links save a lot of space.
The trade-off is familiarity. Some older devices, monitoring tools and staff expect /30, and on a /31 the first address ends in an even number, which surprises people. Whichever you choose, keep all link subnets together in one reserved block, for example the top /26 of the site range, so they are easy to find and to filter.
Summarising routes into supernets
Summarisation (or supernetting) replaces many specific routes with one shorter prefix that covers them all. To find it, write the networks in binary and count how many leading bits they share. 172.16.4.0/24 to 172.16.7.0/24 have third octets 00000100 to 00000111; the first 6 bits match, so the common prefix is 16 + 6 = 22 bits: 172.16.4.0/22.
A summary only works cleanly when the block is aligned and complete. 172.16.5.0 to 172.16.8.0 cannot be one /22, because a /22 must start on a multiple of 4 in the third octet. A summary that is too broad can also attract traffic for subnets that do not exist at that site, so routers usually add a discard route (a route to null0) for the summary to drop such traffic instead of looping it.
- 172.16.4.0/24
- Staff
- 172.16.5.0/24
- Voice
- 172.16.6.0/24
- Servers
- 172.16.7.0/24
- Guests and links
Learn it in 4 short steps
About 40m each. Track them with a timer in your plan.
- 1Sort segments by host count~40m
- 2Allocate largest subnets first~40m
- 3Use /30 or /31 for point-to-point links~40m
- 4Summarise routes into supernets~40m
Key points
- Sort requirements largest first to avoid fragmentation.
- Each subnet must start on a multiple of its block size.
- Point-to-point links use /30 (2 hosts) or /31 (RFC 3021).
- Leave room for growth; renumbering later is painful.
Key terms
Tap a card to flip it. 0/3 known
Examples
import ipaddress
free = ipaddress.ip_network('192.168.1.0/24')
needs = {'staff': 100, 'guests': 50, 'servers': 20}
start = free.network_address
for name, hosts in sorted(needs.items(), key=lambda kv: -kv[1]):
prefix = 32 - (hosts + 2 - 1).bit_length()
net = ipaddress.ip_network(f'{start}/{prefix}')
print(name, net)
start = net.broadcast_address + 1Planning a branch office in 10.50.8.0/21
Needs: staff 400, Wi-Fi guests 200, voice 100, servers 40, management 20, and 4 router links. Step 1: size them: 400 needs /23 (510), 200 needs /24 (254), 100 needs /25 (126), 40 needs /26 (62), 20 needs /27 (30), links /31. Step 2: allocate in order: staff 10.50.8.0/23, guests 10.50.10.0/24, voice 10.50.11.0/25, servers 10.50.11.128/26, management 10.50.11.192/27, links 10.50.11.224/31, .226/31, .228/31 and .230/31. Step 3: everything from 10.50.12.0 to 10.50.15.255 (a whole /22) stays free. Step 4: the branch advertises one summary, 10.50.8.0/21.
Checking a plan for overlaps with Python
Overlapping subnets cause strange half-working routing, so check every plan before using it. Step 1: list each subnet. Step 2: compare every pair with overlaps(). Step 3: confirm each subnet sits inside the site block with subnet_of(). Here a typo put the voice subnet at 10.50.10.128/25, inside the guest /24, and the script catches it.
import ipaddress as ip
from itertools import combinations
site = ip.ip_network('10.50.8.0/21')
plan = {'staff': '10.50.8.0/23', 'guests': '10.50.10.0/24',
'voice': '10.50.10.128/25', 'servers': '10.50.11.128/26'}
nets = {k: ip.ip_network(v) for k, v in plan.items()}
for (a, x), (b, y) in combinations(nets.items(), 2):
if x.overlaps(y):
print(f'OVERLAP: {a} {x} and {b} {y}')
print(all(n.subnet_of(site) for n in nets.values()))Quick reference
- Sort segments by size, allocate largest first, each on a multiple of its block
- Block for h hosts: smallest 2^n with 2^n - 2 at least h
- /31 on router links saves half the space of /30 (RFC 3021)
- Summary = count the leading bits all networks share
- 172.16.4.0/24 to 172.16.7.0/24 summarise to 172.16.4.0/22
- A /22 must start on a multiple of 4 in the third octet
- Keep link and loopback ranges in their own reserved block
Common mistakes
- Placing a small subnet first so larger ones cannot align.
- Overlapping subnets, which breaks routing silently.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Choose the smallest prefix for each segment: 500 hosts, 90 hosts, 30 hosts, 14 hosts, 2 hosts.
- Exercise 2medium
Using 192.168.40.0/24, allocate subnets for 100, 50, 25 and 10 hosts and two /30 links, largest first. List what is left free.
- Exercise 3hard
A router has routes for 10.8.32.0/24, 10.8.33.0/24, 10.8.34.0/24 and 10.8.36.0/24. What is the tightest single summary, and what problem does it cause? Propose a better option.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is VLSM still relevant in the cloud?
- Yes. When you split a VPC CIDR into subnets across availability zones, you are doing VLSM. Planning it well prevents running out of addresses or overlapping with on-premises networks you later connect via VPN.
- Should I use /30 or /31 for router links?
- Use /31 if all your devices and tools support it, since it saves half the space. Use /30 if you have older equipment or want to match an existing convention.
- How much room for growth should I leave?
- A common rule is to size for at least 25 to 50 percent more hosts than today and to keep a large free block per site. Address space inside private ranges is cheap; renumbering is expensive.