toolhq.io

All posts
6 min readby Jameel Haider

Variable length subnet masks (VLSM) done right

VLSM is what you use when a single uniform subnet size wastes half your address space. Instead of splitting a block into equal pieces, you cut each subnet to the size its segment actually needs, so a link with two hosts gets four addresses and a floor with 100 hosts gets 128. The only discipline it demands is allocating in the right order.

Why equal subnets waste space

Say you own 192.168.10.0/24, which is 256 addresses, and you need four segments: 100 hosts, 50 hosts, 25 hosts, and a two host router link. Split the /24 into four equal /26 blocks of 62 usable hosts each, and the first segment does not even fit, while the router link wastes 60 addresses. Equal sizing fails in both directions at once. VLSM fixes this by sizing each subnet independently.

The largest first rule

The one rule that keeps VLSM clean is: allocate the largest subnet first, then the next largest, and so on down to the smallest. If you place small subnets first, their boundaries fall at awkward offsets and a later large subnet no longer has an aligned block to sit in. Starting large means each subnet begins on a boundary that is naturally aligned for the smaller ones that follow.

A full worked allocation

Requirements, sorted largest first, each rounded up to the next power of two plus the network and broadcast overhead:

SegmentHosts neededPrefixBlock sizeNetworkRangeBroadcast
A100/25128192.168.10.0.1–.126192.168.10.127
B50/2664192.168.10.128.129–.190192.168.10.191
C25/2732192.168.10.192.193–.222192.168.10.223
D2/304192.168.10.224.225–.226192.168.10.227

Each subnet starts exactly where the previous one ended, with no gaps and no overlap. After D, addresses 192.168.10.228 through .255 remain free for future growth. The same /24 that could not hold four equal subnets now holds all four with room left.

How to size each subnet

For h hosts, find the smallest power of two that is at least h + 2, accounting for the network and broadcast addresses. One hundred hosts need 128 addresses, which is /25. Fifty need 64, which is /26. Twenty five need 32, which is /27. A point to point link needs two usable, which is four addresses, a /30, or a /31 if your equipment supports it.

Avoiding overlap

The rule that prevents overlap is alignment: a subnet of block size b must start at an address that is a multiple of b. A /26 block of 64 may only start at .0, .64, .128, or .192, never at .100. If you allocate largest first and let each subnet begin immediately after the last, alignment takes care of itself, because every smaller block divides evenly into the space a larger one leaves behind. Overlap only creeps in when you hand pick start addresses by hand or allocate out of order.

Common mistakes

  • Allocating smallest first, which strands odd sized gaps that no larger subnet can use.
  • Forgetting the network and broadcast overhead, so a subnet sized for exactly its host count comes up two addresses short.
  • Reusing a base address across subnets of different sizes, which quietly overlaps ranges.

To plan each subnet and confirm its range, mask, and boundaries before you commit, the Subnet Calculator computes them instantly from a prefix.