VLSM planning: sizing, ordering and leaving room to summarize
Plan a branch with Variable Length Subnet Masking: size each segment with a growth margin, place blocks largest first so nothing is stranded, advertise one summary route with a discard route behind it, and check the plan with Python ipaddress.
Contentsand lesson path
On this page
- The problem: one block for a branch that will grow
- Step 1: Size each segment with its growth margin
- Step 2: Place the blocks largest first
- Step 3: One route to the core, and what sits behind it
- Step 4: Check the plan with Python before it reaches IPAM
- Check your understanding
- Apply it
- Review prompt
Lessons of IPv4 Addressing & Subnetting
- Addresses as 32-bit numbers: binary, masks and prefixes Concept · 20 min
- Worked example: subnetting any prefix without a cheat sheet Worked example · 25 min
- VLSM planning: sizing, ordering and leaving room to summarize Worked example · 25 min
- Special-purpose ranges: private, CGNAT, loopback, link-local and documentation Concept · 15 min
- Lab: on-link vs off-link delivery - ARP, the gateway and ICMP in a capture Lab · 25 min
- Check: timed subnetting and addressing-plan exercise Knowledge check · 8 questions
What you will learn
- Design a VLSM addressing plan for a set of segments with growth margins and summarizable per-site blocks.
Prerequisites: Networking Basics
01. The problem: one block for a branch that will grow
Suppose a regional network team owns 10.72.0.0/16 and gives each site its own block; headquarters already uses 10.72.0.0/22. You are planning a new office, Branch North, with these segments today: guest Wi-Fi with 150 devices, staff with 110, servers with 40, and management with 12 (switches, access points and power units). It also needs two point-to-point WAN links, one to headquarters and one to a backup router.
Company policy sets three constraints. Every segment is sized for 50% growth plus one address for its gateway. Each site is advertised to the core as exactly one route. And the plan must leave room for the next segment without renumbering anything. The questions are how big the branch block must be, where each segment goes inside it, and how to prove there are no overlaps.
The naive plan, a /24 for every segment and link, is easy to read and remember, but here it fails both ways: four /24s plus two links need more than a /22, and two of the segments and both links would sit mostly empty. Variable Length Subnet Masking (VLSM) gives each segment a block sized for its own needs, and it works only if the blocks stay aligned and summarisable.
02. Step 1: Size each segment with its growth margin
For each segment, multiply today's count by 1.5 and round up, add one for the gateway, then pick the smallest prefix whose usable count, 2^h - 2, is at least that number. Apply the margin before choosing the prefix. Power-of-two rounding sometimes leaves headroom by accident and sometimes leaves almost none: the guests' 151 addresses for today already need a /24, which leaves 103 spare, but the staff's 111 fit a /25 with only 15 spare. The margin is the planning decision; the rounding is only arithmetic.
segment today x1.5 rounded up +gateway with growth today only
guests 150 225 226 /24 (254 usable) /24 (254)
staff 110 165 166 /24 (254 usable) /25 (126)
servers 40 60 61 /26 (62 usable) /26 (62)
mgmt 12 18 19 /27 (30 usable) /28 (14)
wan-hq - - 2 /31 (RFC 3021) /31
wan-bkp - - 2 /31 (RFC 3021) /31
with growth: 256 + 256 + 64 + 32 + 2 + 2 = 612 addresses -> needs a /22 (1,024)
today only: 256 + 128 + 64 + 16 + 2 + 2 = 468 addresses -> fits a /23 (512)The margin, not today's head count, decides the size of the branch block: a /22 rather than a /23. It also exposes one judgement call. The servers need 61 addresses in a /26 that has 62, so only one server beyond the forecast still fits. If that forecast is shaky, a /25 for the servers costs 64 more addresses out of a plentiful private range and avoids a renumbering later. The 50% figure is this company's policy, not a standard; choose a margin from your own growth forecast and from how painful renumbering would be. Point-to-point links get no margin, because a link between two routers always has exactly two ends. The next free aligned /22 in the region is 10.72.4.0/22, covering third-octet values 4 to 7.
03. Step 2: Place the blocks largest first
Every block must start at a multiple of its own size. The simplest allocator keeps a cursor at the first free address, moves it up to the next valid boundary for each block, and places the block there. Sort the blocks from largest to smallest and that cursor never has to move: after placing two /24s (256 addresses each), it has advanced by 512, a multiple of 64, so the /26 fits right there; after the /26 it sits on a multiple of 32 for the /27, and so on. In general, the cursor has moved by a sum of block sizes that are all multiples of the next, smaller size, so it is already aligned. No gap appears anywhere.
Any other order can force the cursor to jump forward, and every jump leaves a gap. Take the order in which the segments appear in the VLAN list, which is how a ticket queue or spreadsheet usually presents them: management first, then guests, servers and staff. Management takes 10.72.4.0/27; the guests' /24 cannot start at 10.72.4.32, so it jumps to 10.72.5.0; the servers land at 10.72.6.0/26; the staff /24 jumps to 10.72.7.0; and the WAN links fall off the end of the block at 10.72.8.0. The plan needs 612 addresses and the block has 1,024, yet it does not fit, because 224 addresses were skipped between 10.72.4.32 and 10.72.4.255, and 192 more between 10.72.6.64 and 10.72.6.255. An allocator that searches backwards for the lowest free aligned slot could fill those gaps, but the free space would end up in scattered pieces.
third.fourth octet block segment
4.0 - 4.255 10.72.4.0/24 guests
5.0 - 5.255 10.72.5.0/24 staff
6.0 - 6.63 10.72.6.0/26 servers
6.64 - 6.95 10.72.6.64/27 mgmt
6.96 - 6.99 two /31s wan-hq 6.96/31, wan-bkp 6.98/31
6.100 - 7.255 free 6.100/30 6.104/29 6.112/28 6.128/25 7.0/24Largest first also puts all the free space at the top of the block, in the biggest aligned pieces possible: a whole 10.72.7.0/24 and a 10.72.6.128/25. The next new segment of up to 254 hosts fits without moving anything.
04. Step 3: One route to the core, and what sits behind it
Because every Branch North segment sits inside one aligned block, the branch router can advertise a single summary route, 10.72.4.0/22, to the core. RFC 4632 (section 4.1) makes this point: giving a site one contiguous power-of-two block lets its routing information be aggregated into one prefix. The core carries one route per site instead of one per VLAN, and a new VLAN at the branch changes nothing there.
Unused addresses inside a summary need care. The core sends everything in 10.72.4.0/22 to the branch, including unused addresses such as 10.72.7.10. With no more specific route for one, the branch router follows its own default route back toward the core, and the packet bounces between them until its TTL runs out. RFC 4632 (section 5.1) therefore says a router generating an aggregate must discard packets that match it but no more specific route. On Linux that is a blackhole route, ip route add blackhole 10.72.4.0/22; the VLANs' connected routes are more specific, so they still win for addresses in use.
What if Branch North outgrows its /22? Shortening a prefix by one bit merges a block with exactly one aligned partner of the same size. For 10.72.4.0/22 the partner is 10.72.0.0/22 (the script in Step 4 prints the /21 around the site, 10.72.0.0/21), and it belongs to headquarters. So the branch must either advertise a second route for new space elsewhere or be renumbered into a fresh aligned /21, such as 10.72.8.0/21. If a site is likely to double, reserve the aligned double from the start and keep its second half free.
When not to summarise. Forwarding uses the longest matching prefix, so RFC 4632 notes that destinations reachable through more than one path must be announced explicitly. If one Branch North VLAN can also be reached through a second provider or a direct link to another site, advertise it on its own as well as the summary. And a summary must never cover another site's addresses, because it would attract that site's traffic.
05. Step 4: Check the plan with Python before it reaches IPAM
Before a plan goes into an IP address management (IPAM) system or an infrastructure-as-code file, check it with a script. Fixing an overlap after servers have static addresses, firewall rules and DNS records means downtime. The script below does the whole worked example: size() applies the policy, allocate() is the cursor allocator from Step 2, it tries the VLAN-list order and then largest first, asserts that no two blocks overlap, computes the free space with address_exclude() and collapse_addresses(), and prints the /21 around the site with supernet(). Save it as plan.py and run python3 plan.py; it needs only Python 3.
import ipaddress
site = ipaddress.ip_network("10.72.4.0/22")
# segments in VLAN-ID order: (name, hosts today)
today = [("mgmt", 12), ("guests", 150), ("servers", 40), ("staff", 110)]
def size(hosts):
"""Smallest prefix for today's hosts + 50% growth (rounded up) + 1 gateway."""
need = -(-hosts * 3 // 2) + 1
host_bits = 2
while 2**host_bits - 2 < need:
host_bits += 1
return need, 32 - host_bits
rows = [(name, *size(n)) for name, n in today] + [("wan-hq", 2, 31), ("wan-bkp", 2, 31)]
def allocate(order):
cursor, placed = int(site.network_address), []
for name, need, plen in order:
block = 2 ** (32 - plen)
cursor = -(-cursor // block) * block # move up to the block's boundary
net = ipaddress.ip_network((cursor, plen))
if not net.subnet_of(site):
return placed, f"{name} lands at {net}, outside {site}"
placed.append((name, need, net))
cursor += block
return placed, "fits"
placed, result = allocate(rows)
print("VLAN-ID order:", " ".join(str(net) for _, _, net in placed))
print(" ->", result)
plan, result = allocate(sorted(rows, key=lambda r: r[2])) # largest block first
print("largest first:", result)
for name, need, net in plan:
print(f" {name:8} need={need:3} -> {str(net):15} usable={len(list(net.hosts()))}")
nets = [net for _, _, net in plan]
assert not any(a.overlaps(b) for i, a in enumerate(nets) for b in nets[i + 1:])
free = [site]
for net in nets:
free = [part for f in free
for part in (f.address_exclude(net) if net.subnet_of(f) else [f])]
print("free:", ", ".join(str(n) for n in ipaddress.collapse_addresses(free)))
print("one route to the core:", site, "| the /21 around it:", site.supernet())VLAN-ID order: 10.72.4.0/27 10.72.5.0/24 10.72.6.0/26 10.72.7.0/24
-> wan-hq lands at 10.72.8.0/31, outside 10.72.4.0/22
largest first: fits
guests need=226 -> 10.72.4.0/24 usable=254
staff need=166 -> 10.72.5.0/24 usable=254
servers need= 61 -> 10.72.6.0/26 usable=62
mgmt need= 19 -> 10.72.6.64/27 usable=30
wan-hq need= 2 -> 10.72.6.96/31 usable=2
wan-bkp need= 2 -> 10.72.6.98/31 usable=2
free: 10.72.6.100/30, 10.72.6.104/29, 10.72.6.112/28, 10.72.6.128/25, 10.72.7.0/24
one route to the core: 10.72.4.0/22 | the /21 around it: 10.72.0.0/2106. Check your understanding
07. Apply it
Now do the skill's practice task. From 10.20.0.0/16, plan a headquarters with five VLANs (500, 200, 110, 50 and 20 hosts today), two branches that each start with two /24-sized segments, and the three point-to-point links between the sites. Apply a 50% margin to every VLAN, give each site one aligned block that it can advertise as a single summary, and keep each site's growth partner free where you can. Record every prefix, its usable range and its gateway in an IPAM table, then adapt plan.py to check that no two prefixes overlap and that every VLAN sits inside its site's summary.
Next, special-purpose ranges explains which blocks such a plan may use, and which belong to providers, hosts or documentation.
08. Review prompt
Explain from memory why allocating largest first never leaves a gap, why the growth margin is applied before choosing a prefix, the two conditions that let a site be advertised as one route, what the discard route behind a summary prevents, and why 10.72.4.0/22 cannot simply grow into a /21.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.