VLSM and route summarization
VLSM (Variable Length Subnet Mask) gives every team a subnet that fits its size instead of equal blocks, and route summarization advertises many continuous subnets as one shorter prefix. Together they give you an address plan with little waste and small, stable routing tables.
11.1 Why is it used?
- Example office: 192.168.31.0/24 with Sales 100 hosts, Dev 50, HR 20 and a WAN link to the HQ core router.
- Equal /26 subnets hold only 62 hosts each, so Sales (100) simply does not fit.
- The WAN link needs 2 IPs but would also get 62, so 60 addresses are wasted.
- Without summarization the HQ core router keeps one route per office subnet, and the table grows with every new subnet.
11.2 How VLSM works
- VLSM = subnets of different sizes inside the same network; each subnet has its own mask.
- Usable hosts = 2^(32 - prefix) - 2, because the network and broadcast addresses never go to a host.
- Pick the smallest block where hosts + 2 fit: 100 -> /25, 50 -> /26, 20 -> /27, 2 -> /30.
- A packet from a Sales PC to HR goes to the office router, which forwards it into the correct subnet.
| Team | Hosts needed | Prefix | Usable hosts | Range |
|---|---|---|---|---|
| Sales | 100 | 192.168.31.0/25 | 126 | .0 - .127 |
| Dev | 50 | 192.168.31.128/26 | 62 | .128 - .191 |
| HR | 20 | 192.168.31.192/27 | 30 | .192 - .223 |
| WAN link | 2 | 192.168.31.224/30 | 2 | .224 - .227 |
Free for growth: 192.168.31.228 to 192.168.31.255.
11.3 Building an address plan: 4 steps
- Step 1
1.Sort requirements largest first: 100, 50, 20, 2
- Step 2
2.Choose block size (hosts + 2 fit): /25, /26, /27, /30
- Step 3
3.Start the biggest subnet at the range start: Sales = 192.168.31.0
- Step 4
4.Each next subnet starts at previous broadcast + 1: .128, .192, .224
- Step 5
5.Leftover space stays free for growth: .228 to .255
Placing big subnets first keeps every boundary aligned automatically
11.4 Checking the plan with ipcalc
- ipcalc -n prints the network address, -b prints the broadcast address (BusyBox ipcalc in the lab).
- Each subnet starts right after the previous one's broadcast: Sales ends at .127, Dev starts at .128.
ipcalc -nb 192.168.31.10/25ipcalc -nb 192.168.31.130/26ipcalc -nb 192.168.31.194/27ipcalc -nb 192.168.31.226/30$ ipcalc -nb 192.168.31.10/25BROADCAST=192.168.31.127NETWORK=192.168.31.0$ ipcalc -nb 192.168.31.130/26BROADCAST=192.168.31.191NETWORK=192.168.31.128$ ipcalc -nb 192.168.31.194/27BROADCAST=192.168.31.223NETWORK=192.168.31.192$ ipcalc -nb 192.168.31.226/30BROADCAST=192.168.31.227NETWORK=192.168.31.224On the office router (built with network namespaces inside one Docker container) every subnet shows a different prefix length, /25 down to /30: that is VLSM.
ip netns exec office ip route192.168.31.0/25 dev eth-sales proto kernel192.168.31.128/26 dev eth-dev proto kernel192.168.31.192/27 dev eth-hr proto kernel192.168.31.224/30 dev eth-wan proto kernel11.5 Route summarization
- The HQ core router must reach every office subnet; without summarization it holds three routes, all with next hop = office router.
- All three subnets sit inside 192.168.31.0/24, so one route 192.168.31.0/24 via the office router is enough.
- Whatever the destination (Sales or HR), the same single route matches and the office router does the rest.
- Longest-prefix match still applies: a more specific route (like the connected /30 WAN link) wins over the summary.
- Step 1
1.Packet for 192.168.31.194 (HR) arrives at HQ core
- Step 2
2.Core lookup matches 192.168.31.0/24 via 192.168.31.225
- Step 3
3.Forwarded over the /30 WAN link to the office router
- Step 4
4.Office router matches 192.168.31.192/27 (eth-hr)
- Step 5
5.Delivered to the HR PC; reply TTL 63 = one router crossed
ip netns exec core ip route# inside the core namespace: replace three routes with one summaryip route del 192.168.31.0/25ip route del 192.168.31.128/26ip route del 192.168.31.192/27ip route add 192.168.31.0/24 via 192.168.31.225ip netns exec core ip routeping -c 2 192.168.31.194ping -c 1 192.168.31.240$ ip netns exec core ip route192.168.31.0/25 via 192.168.31.225192.168.31.128/26 via 192.168.31.225192.168.31.192/27 via 192.168.31.225192.168.31.224/30 dev eth-wan proto kernel$ ip netns exec core ip route192.168.31.0/24 via 192.168.31.225192.168.31.224/30 dev eth-wan proto kernel$ ping -c 2 192.168.31.19464 bytes from 192.168.31.194: icmp_seq=1 ttl=6364 bytes from 192.168.31.194: icmp_seq=2 ttl=632 packets transmitted, 2 received, 0% packet loss$ ping -c 1 192.168.31.240From 192.168.31.225 icmp_seq=1 Destination Net Unreachable1 packets transmitted, 0 received, +1 errors192.168.31.240 is not assigned to any team, but the summary still sends it to the office router, which has no route for it and replies Destination Net Unreachable.
11.6 Supernetting
- Same idea at a bigger scale: four branches 172.16.0.0/24 ... 172.16.3.0/24 = one 172.16.0.0/22.
- The regional router advertises one supernet to the ISP/HQ instead of four routes.
- Rules: networks must be continuous, their count a power of two, and the first network must start on the block boundary.
ipcalc -n 172.16.0.0/22ipcalc -n 172.16.3.0/22ipcalc -n 172.16.4.0/22ipcalc -nb 172.16.0.0/22$ ipcalc -n 172.16.0.0/22NETWORK=172.16.0.0$ ipcalc -n 172.16.3.0/22NETWORK=172.16.0.0$ ipcalc -n 172.16.4.0/22NETWORK=172.16.4.0$ ipcalc -nb 172.16.0.0/22BROADCAST=172.16.3.255NETWORK=172.16.0.0- 172.16.0.0 and 172.16.3.0 both give network 172.16.0.0 at /22, so both are inside the supernet.
- 172.16.4.0 gives a different network, so it is outside; the supernet ends at 172.16.3.255.
11.7 Comparison: VLSM vs summarization
| Point | VLSM | Route summarization / supernetting |
|---|---|---|
| Direction | Splits one network into smaller subnets | Combines many subnets into one route |
| Prefix | Longer prefixes (/25, /26, /27, /30) | Shorter prefix (/24, /22) |
| Goal | Less address waste | Smaller routing table, fewer updates |
| Where it matters | Address planning inside a site | Between routers: core, ISP, HQ |
| Lab example | Office router: 4 subnets | Core: 3 routes -> 192.168.31.0/24 |
11.8 Benefits of summarization
- Smaller routing table: less memory, less CPU, faster lookup.
- Fewer routing updates: a subnet going up/down inside the summary does not travel outside it.
- More stability: one link flap does not shake the whole network.
- Easier troubleshooting: a clean, predictable address plan.
11.9 Common mistakes
- Allocating small subnets first: later big subnets no longer land on a valid boundary.
- Forgetting the +2 (network + broadcast): 30 hosts needs /27 (32 - 2 = 30), not /28.
- Leaving no room to grow: if a 30-host team will grow, choose /26 (62 hosts).
- Assuming a summary means everything is reachable: unused ranges (like .240) are forwarded and then dropped.
- Summarizing non-continuous networks, or a block that does not start on its boundary.
11.10 Interview tips
- VLSM: one network, subnets of different sizes, less waste.
- Summarization: many continuous subnets advertised as one shorter prefix, so a small table and a stable network.
- Always plan largest to smallest; each subnet starts at previous broadcast + 1.
- Four consecutive /24s = one /22, only if aligned and a power of two.
- Mention the trade-off: a summary can attract traffic for unused addresses (Destination Net Unreachable).