Blog/developer

VLSM Explained: Variable Length Subnet Masking

By Yurlie TeamAugust 16, 20266 min read 1 views
VLSM Explained: Variable Length Subnet Masking

VLSM Explained: Variable Length Subnet Masking

Classic subnetting has a wasteful assumption baked into it: every subnet in a network gets the same size, whether it needs 2 hosts or 200. A point-to-point WAN link that only ever needs 2 usable addresses ends up burning a full /24 with 254 wasted addresses, just because the rest of the network also uses /24. Variable Length Subnet Masking, or VLSM, exists to fix exactly this problem.

VLSM lets you subnet a subnet. Instead of applying one mask across an entire address block, you apply different masks to different parts of it based on how many hosts each segment actually needs. The result is address space that fits the network instead of the other way around.

Why Fixed-Length Subnetting Falls Short

With traditional subnetting, you pick one subnet mask and apply it uniformly. Say you are given 192.168.1.0/24 and need to support 6 subnets. You would borrow 3 bits from the host portion, giving you 8 equal subnets of /27 each, 30 usable hosts per subnet.

That works fine if every subnet genuinely needs around 30 hosts. But real networks are not uniform. A head office LAN might need 100 hosts, a branch office needs 20, and a router-to-router link needs exactly 2. Forcing all of them into the same /27 means the head office runs out of addresses while the point-to-point link wastes 28 of its 30 usable addresses. Across a whole network, this adds up to a lot of unusable space.

How VLSM Solves It

VLSM breaks the one-mask-fits-all rule. You start with your largest subnet requirement, allocate a block sized to fit it, and then subnet the remaining address space again for the next requirement, repeating until every segment has a block just large enough for its host count plus reasonable headroom.

The core rule to remember: allocate from largest to smallest. If you assign small subnets first, you fragment the address space and often cannot fit the larger blocks later, since VLSM subnets need to sit on address boundaries aligned to their own size.

Worked Example

Suppose you are given 192.168.10.0/24 and need to support these segments:

  • LAN A: 100 hosts
  • LAN B: 50 hosts
  • LAN C: 20 hosts
  • Link 1 (router to router): 2 hosts
  • Link 2 (router to router): 2 hosts

Step 1: Sort requirements from largest to smallest

100, 50, 20, 2, 2.

Step 2: Allocate the largest block first

LAN A needs 100 usable hosts. The smallest block that covers this is a /25, which gives 2^(32-25) - 2 = 126 usable hosts.

  • LAN A: 192.168.10.0/25, range 192.168.10.1 to 192.168.10.126, broadcast 192.168.10.127

Step 3: Allocate the next block from what remains

The next available address is 192.168.10.128. LAN B needs 50 hosts, which fits in a /26, giving 62 usable hosts.

  • LAN B: 192.168.10.128/26, range 192.168.10.129 to 192.168.10.190, broadcast 192.168.10.191

Step 4: Continue allocating

Next available address is 192.168.10.192. LAN C needs 20 hosts, which fits in a /27, giving 30 usable hosts.

  • LAN C: 192.168.10.192/27, range 192.168.10.193 to 192.168.10.222, broadcast 192.168.10.223

Step 5: Allocate the point-to-point links

Next available address is 192.168.10.224. Each link needs exactly 2 usable hosts, which fits in a /30, giving exactly 2 usable hosts.

  • Link 1: 192.168.10.224/30, range 192.168.10.225 to 192.168.10.226, broadcast 192.168.10.227
  • Link 2: 192.168.10.228/30, range 192.168.10.229 to 192.168.10.230, broadcast 192.168.10.231

Final allocation table

SegmentHosts NeededSubnetMaskUsable RangeBroadcast
LAN A100192.168.10.0/25255.255.255.128.1 to .126.127
LAN B50192.168.10.128/26255.255.255.192.129 to .190.191
LAN C20192.168.10.192/27255.255.255.224.193 to .222.223
Link 12192.168.10.224/30255.255.255.252.225 to .226.227
Link 22192.168.10.228/30255.255.255.252.229 to .230.231

Out of the original /24, addresses from 192.168.10.232 through 192.168.10.255 remain unallocated, ready for future growth without needing to renumber anything already deployed.

The Host Count Formula

For any subnet mask, the number of usable host addresses is:

usable hosts = 2^(32 - prefix length) - 2

The minus 2 accounts for the network address and the broadcast address, both of which are reserved and cannot be assigned to a host. The one common exception is /31 links, defined in RFC 3021, which are used specifically for point-to-point connections and treat both addresses in the pair as usable, since there is no broadcast concept needed on a link with exactly two endpoints.

Common Mistakes to Watch For

  • Allocating small to large. This is the single most common VLSM error. Starting with your smallest subnets first tends to fragment address space so that larger blocks no longer fit on a valid boundary.
  • Forgetting that subnets must align to their own size. A /26 block must start at an address that is a multiple of 64. You cannot just start it anywhere convenient.
  • Underestimating growth. Sizing a subnet to the exact current host count leaves zero room to add a single device later without a redesign. Round up to the next power of two with some margin.
  • Confusing usable hosts with total addresses. A /30 has 4 total addresses but only 2 usable ones. This trips up a lot of people sizing point-to-point links.

VLSM vs CIDR

VLSM and CIDR (Classless Inter-Domain Routing) are closely related but solve different problems. VLSM is about subnetting within an organization, allocating differently sized blocks to different internal segments. CIDR is about how those blocks get represented and routed, using the prefix notation (like /24 or /27) instead of the old class-based A, B, C system, and how routes can be aggregated to reduce the size of routing tables. In practice, VLSM is what you do when designing a network, and CIDR notation is the language you use to describe the result.

When VLSM Matters Most

VLSM is essential in any network with a mix of segment sizes, which is to say, almost every real network. It matters most in:

  • Enterprise networks with departments of varying size
  • WAN designs full of point-to-point router links
  • ISP address allocation, where wasting address space directly costs money
  • Any environment still running on limited IPv4 space, where every wasted address is a real constraint

Calculate Your Own VLSM Allocations Instantly

Skip the manual binary math. Plan subnet boundaries, usable host ranges, and broadcast addresses for every segment in your network with the free Yurlie Subnet Calculator.

Total Views: 1Category: developer

Try Yurlie Online Developer Tools

Run CIDR calculations, JSON formatting, Base64 encoding, and UUID generation instantly in your browser.

Explore Tools →