Variable Length Subnet Masks in Practice
Carve one address block into subnets of different sizes with VLSM, using a largest-first method and a full worked example.
Key takeaways
- VLSM lets each subnet have its own mask, so address space is spent in proportion to need.
- Allocating the largest subnets first keeps every block aligned to a multiple of its own size.
- Each block needs room for the devices, the gateway, the network address and the broadcast address, plus growth.
- Routing protocols must carry the mask with every route, and all modern ones in common use do.
Variable length subnet masking, or VLSM, means using different prefix lengths for different subnets cut from the same block. A segment with 100 devices gets a large piece, a link between two routers gets a tiny one, and nothing forces them to match.
The method is simple: sort your needs from largest to smallest, give each the smallest block that fits, and place the blocks one after another. Follow that order and every block lands on a valid boundary without gaps or overlaps.
Why equal slices fall short
Suppose you have 192.168.50.0/24 and need segments for 100 staff devices, 50 guests, 25 phones, 10 servers and one router-to-router link.
With equal-sized subnets, the largest need sets the size. One hundred devices need a /25, and a /24 holds only two of those. You cannot make five. Dividing into eight /27 blocks gives enough subnets but only 30 hosts each, too small for staff or guests.
With different sizes, everything fits with room to spare.
Step 1: size each need
For each segment, add the network and broadcast addresses to the host count, which must already include the gateway. Then round up to a power of two.
| Segment | Hosts needed (with gateway) | Plus 2 | Block | Prefix |
|---|---|---|---|---|
| Staff | 100 | 102 | 128 | /25 |
| Guests | 50 | 52 | 64 | /26 |
| Phones | 25 | 27 | 32 | /27 |
| Servers | 10 | 12 | 16 | /28 |
| Router link | 2 | 4 | 4 | /30 |
Look at headroom as you go. The phone block holds 30 usable addresses against a need of 25. That is acceptable if phone numbers are stable. If the team is hiring, you might step up now, while it costs nothing.
Step 2: allocate largest first
Start at the bottom of the block and stack the pieces in order of size.
| Segment | Subnet | Usable range | Broadcast |
|---|---|---|---|
| Staff | 192.168.50.0/25 | .1 to .126 | .127 |
| Guests | 192.168.50.128/26 | .129 to .190 | .191 |
| Phones | 192.168.50.192/27 | .193 to .222 | .223 |
| Servers | 192.168.50.224/28 | .225 to .238 | .239 |
| Router link | 192.168.50.240/30 | .241 to .242 | .243 |
What remains is .244 through .255: twelve addresses. Written as aligned blocks, that is 192.168.50.244/30 and 192.168.50.248/29. List them as free so someone can use them later.
Why the order matters
A block must start at a multiple of its size. A block of 128 addresses can begin only at 0 or 128 within a /24. If you place the tiny router link first, at .0 to .3, the staff block can no longer start at .0. It has to start at .128, leaving a ragged hole from .4 to .127 that must be filled with smaller pieces.
When you go from large to small, each finished block ends on a boundary that is also valid for every smaller size. Alignment takes care of itself.
You can place things in other orders if you check alignment by hand. Some planners put small infrastructure blocks at the top of the range and large user blocks at the bottom, leaving free space in the middle where either can grow. That is a sound choice for networks you expect to change.
Configuring the pieces
On the router, each segment becomes an interface or VLAN interface with the first usable address of its block and the matching mask. Using the plan above on a Cisco-style command line:
interface vlan 10
ip address 192.168.50.1 255.255.255.128
interface vlan 20
ip address 192.168.50.129 255.255.255.192
interface vlan 30
ip address 192.168.50.193 255.255.255.224
interface vlan 40
ip address 192.168.50.225 255.255.255.240 Other platforms use different commands and often accept the slash form. The thing to check is the same everywhere: each interface has the mask of its own block, not the mask of the parent /24.
If someone types 255.255.255.0 on the guest interface, many routers will refuse because it overlaps another interface. A host with that mistake will not complain. It will simply believe that the whole /24 is local and fail to reach servers in the other blocks, while internet access keeps working. That combination of symptoms is a strong hint to check masks.
DHCP scopes need the same care. Each scope gets the block's mask, its own gateway and a pool that stays between the first and last usable addresses, minus whatever you hold back for fixed devices. In the phone block, a pool of .200 to .222 leaves .194 to .199 for static equipment.
Point-to-point links: /30 or /31
A link between two routers needs two addresses. The traditional /30 provides four, of which two are wasted on network and broadcast. RFC 3021 defines the use of /31 on point-to-point links, where both addresses are assigned to the two ends. Most business-grade routing equipment supports it. Both ends must agree, so confirm support before relying on it.
Router loopback addresses are normally /32, a block of one.
Letting routing protocols know
With one fixed mask everywhere, a router could in principle assume it. With variable masks it must be told the prefix length of every route. The early protocol RIP version 1 did not send masks, which made VLSM unworkable with it. RIP version 2, OSPF, IS-IS, EIGRP and BGP all carry prefix lengths. Static routes include the mask by definition.
Routers choose among overlapping routes by longest prefix match: the most specific entry wins. A router holding routes for both 192.168.50.0/24 and 192.168.50.224/28 sends traffic for .230 along the /28. This is what makes hierarchical plans work.
Keeping blocks summarizable
If your network spans sites, assign each site one aligned parent block and do VLSM inside it. A branch given 10.20.16.0/20 can be cut up however it likes, while the rest of the company needs only one route to reach it. Scatter a branch's subnets across unrelated ranges and every router needs every entry. Route summarization covers the arithmetic.
A second example: splitting what is left
A month later you need a new segment for 6 cameras, with a gateway: 7 hosts, plus 2, is 9, so a block of 16. The free space was .244/30 and .248/29, and neither holds 16. Together they are 12 addresses, and they are not a single aligned block anyway.
Your options are to resize an existing segment, use a second /24, or accept a /29 with 6 usable addresses, which is one short once the gateway is counted. Moving to a second block is usually the sensible answer on a private network. This is the main weakness of tight allocation: it saves addresses today and leaves little flexibility tomorrow.
Growing a subnet later
Sometimes a block can grow in place. A /26 can become a /25 if the neighboring /26 that completes its parent is free. For 192.168.50.0/26, the partner is .64/26. For 192.168.50.64/26, the partner is .0/26, so growth would move the network address down.
The guest block in the example, .128/26, would need .192/26 to become .128/25, and phones and servers live there. It cannot grow without moving them.
When you do resize, shorten DHCP lease times a day or so beforehand so clients pick up the new mask quickly. Restore the usual lease time afterward.
Keeping the records
A VLSM plan is only as good as its list. For every block, record the prefix, the purpose, the gateway, the VLAN and the date assigned. For free space, record aligned prefixes, not vague notes such as "the top end". A spreadsheet works for a few dozen entries. Larger networks use IP address management software, which refuses overlapping assignments and shows utilization.
Review the list occasionally against reality. Routing tables, DHCP leases and switch configurations show what is in use, and blocks that were reserved for projects that never happened can return to the pool.
When not to use it
On private networks with plenty of space, a uniform /24 per segment is often better. Everyone can read it, and mistakes are rarer. VLSM earns its keep when:
- You hold a limited block of public addresses.
- A cloud network or provider gives you a fixed small range.
- You have many point-to-point links.
- A parent block must be preserved for summarization.
A mixed approach is common: /24 for user segments, smaller blocks only for links and infrastructure. Planning a small office scheme shows the uniform style.
Checking a plan before you build it
Walk the finished table with three tests. First, each starting address must divide evenly by its block size: .192 divides by 32, .224 by 16 and .240 by 4. Second, each block's broadcast address must be lower than the next block's start. Third, the total of all block sizes, including free ones, must equal the size of the parent. In the example, 128 + 64 + 32 + 16 + 4 + 4 + 8 comes to 256.
If the total falls short, some addresses are missing from your records. If it exceeds the parent, two blocks overlap somewhere.
Mistakes to avoid
- Overlaps.
.192/26and.224/27cannot both be assigned as separate segments, because the first contains the second. Check each new block against all existing ones. - Misaligned starts.
192.168.50.100/26is not a block boundary. The block containing it begins at.64. - Forgetting the gateway. Fourteen usable addresses in a
/28means thirteen for devices. - Mismatched masks on one segment. After resizing, update the gateway, the DHCP scope and every manually configured device.
- No free-space record. Keep a list of unallocated prefixes.
The CIDR set algebra tool can subtract allocated blocks from a parent and show what remains, which is a quick way to catch overlaps and forgotten space. If the block size arithmetic still feels slow, review how to calculate subnet masks first.