Variable Length Subnet Masking (VLSM) is just subnetting where the pieces are different sizes. It matters because real networks are lopsided: a user VLAN might need 500 addresses while a router-to-router link needs two. Giving both a /24 wastes a thousand addresses. This guide treats VLSM as a repeatable design process and works a full example end to end.
Suppose you carve 10.0.0.0/24 into eight equal /27 subnets (30 hosts each). A point-to-point link between two routers uses 2 of those 30 addresses; the other 28 are stranded — you cannot lend them to the busy user segment next door, because they belong to a different subnet. Multiply that across dozens of links and you run out of space in a block that is mostly empty. VLSM fixes this by sizing each subnet to its actual need.
There is one rule that makes VLSM work without overlaps: allocate the largest subnet first, then the next largest, and so on. Each subnet is placed at the next free, correctly aligned boundary. Sorting largest-to-smallest guarantees alignment falls into place naturally; doing it in the wrong order leaves awkward gaps.
The only calculation in VLSM is turning a host count into a prefix. A subnet with n host bits has 2n addresses, two of which (network and broadcast) cannot be given to hosts. So you need the smallest n where 2n − 2 ≥ hosts, and the prefix is 32 − n:
prefix = 32 − ceil( log2(hosts + 2) ) hosts = 50 → 50 + 2 = 52 → next power of two 64 = 2^6 → /26
Nobody does the logarithm in an exam. Memorise this table instead:
| Hosts needed (up to) | Prefix | Mask | Block size |
|---|---|---|---|
| 2 | /30 | 255.255.255.252 | 4 |
| 6 | /29 | 255.255.255.248 | 8 |
| 14 | /28 | 255.255.255.240 | 16 |
| 30 | /27 | 255.255.255.224 | 32 |
| 62 | /26 | 255.255.255.192 | 64 |
| 126 | /25 | 255.255.255.128 | 128 |
| 254 | /24 | 255.255.255.0 | 256 |
| 510 | /23 | 255.255.254.0 | 512 |
| 1,022 | /22 | 255.255.252.0 | 1,024 |
| 2,046 | /21 | 255.255.248.0 | 2,048 |
| 4,094 | /20 | 255.255.240.0 | 4,096 |
Find the first row whose host count is at least your requirement. A segment that needs 31 hosts does not fit a /27 (30 usable), so it gets a /26. The hosts to prefix tool does the lookup for any count.
You are given 172.16.0.0/22 (1,024 addresses) and these requirements:
| Segment | Hosts needed | Smallest prefix | Block size |
|---|---|---|---|
| Office LAN | 400 | /23 | 512 |
| Wi-Fi | 200 | /24 | 256 |
| Servers | 60 | /26 | 64 |
| Management | 20 | /27 | 32 |
| Router link | 2 | /30 | 4 |
A 400-host segment needs 402 addresses including network and broadcast; the next power of two is 512, a /23. Wi-Fi's 200 rounds up to 256, a /24. Now allocate largest first, starting at 172.16.0.0:
Office LAN /23 172.16.0.0 → 172.16.1.255 (510 usable) Wi-Fi /24 172.16.2.0 → 172.16.2.255 (254 usable) Servers /26 172.16.3.0 → 172.16.3.63 ( 62 usable) Management /27 172.16.3.64 → 172.16.3.95 ( 30 usable) Router link /30 172.16.3.96 → 172.16.3.99 ( 2 usable)
Each block begins exactly where the last one ended, and each start address is a multiple of its own block size — that is what "aligned" means. Total consumed: 512 + 256 + 64 + 32 + 4 = 868 addresses out of 1,024, leaving 172.16.3.100 through 172.16.3.255 (156 addresses) free for growth. Efficiency: about 85%.
This is the shape of most exam and lab questions. You are given 192.168.1.0/24 and asked to address two LANs, a guest network, a printer VLAN and two router-to-router links:
| Segment | Hosts needed | Prefix | Mask |
|---|---|---|---|
| Sales | 100 | /25 | 255.255.255.128 |
| Engineering | 50 | /26 | 255.255.255.192 |
| Guest Wi-Fi | 25 | /27 | 255.255.255.224 |
| Printers | 10 | /28 | 255.255.255.240 |
| WAN link A | 2 | /30 | 255.255.255.252 |
| WAN link B | 2 | /30 | 255.255.255.252 |
The list is already sorted largest first, so allocate from 192.168.1.0 and let each block start where the last one ended:
Segment Network First host Last host Broadcast Sales 192.168.1.0/25 192.168.1.1 192.168.1.126 192.168.1.127 Engineering 192.168.1.128/26 192.168.1.129 192.168.1.190 192.168.1.191 Guest Wi-Fi 192.168.1.192/27 192.168.1.193 192.168.1.222 192.168.1.223 Printers 192.168.1.224/28 192.168.1.225 192.168.1.238 192.168.1.239 WAN link A 192.168.1.240/30 192.168.1.241 192.168.1.242 192.168.1.243 WAN link B 192.168.1.244/30 192.168.1.245 192.168.1.246 192.168.1.247
Used: 128 + 64 + 32 + 16 + 4 + 4 = 248 of 256 addresses. 192.168.1.248/29 is left over, enough for one more small segment or two more /30 links. With fixed-size subnets the same job would need six /25s, three times the whole /24.
Two checks catch almost every mistake. First, no overlap: each subnet's broadcast address must be lower than the next subnet's network address. Second, alignment: each network address modulo its block size must be zero (e.g. a /26's network must be a multiple of 64). The VLSM solver enforces both and shows the allocation efficiency; the subnet splitter handles the simpler case where every segment is the same size.
A favourite exam question gives you a list of subnets and asks which ones overlap. Turn each one into a range (network address to broadcast address) and compare the ranges. Take these four:
10.1.1.0/26 → 10.1.1.0 to 10.1.1.63 10.1.1.64/27 → 10.1.1.64 to 10.1.1.95 10.1.1.96/28 → 10.1.1.96 to 10.1.1.111 10.1.1.48/28 → 10.1.1.48 to 10.1.1.63 ← inside 10.1.1.0/26
10.1.1.48/28 overlaps, because its whole range sits inside the /26. The quick way to spot it: a /26 covers 64 addresses from its network address, so any other subnet starting between .0 and .63 collides with it. The membership checker answers "is this address inside that subnet?" for any pair.
172.16.0.0, and the next /23 cannot start until 172.16.2.0, because a /23 must begin on a multiple of 512. The 508 addresses in between become alignment padding.| FLSM (fixed length) | VLSM (variable length) | |
|---|---|---|
| Masks | one mask for every subnet | a mask sized to each subnet |
| Address use | wasteful on small segments | close to what each segment needs |
| Planning | divide by a power of two and you are done | sort, size and align each block |
| Routing protocol | works even with classful ones (RIPv1) | needs a classless one (OSPF, EIGRP, RIPv2...) |
FLSM is the right tool when every segment really is the same size, and the subnet splitter does it in one step. As soon as sizes differ, VLSM wins.
A VLSM plan only works if the routers can tell a /26 from a /27, so the routing protocol has to send the prefix length with every route. Protocols that do are called classless:
no auto-summary under the routing process, or routers will advertise one summary route for subnets they cannot all reach.Lab exercises such as "design and implement a VLSM addressing scheme" follow the same three steps whatever the topology.
Router(config)# interface g0/0 Router(config-if)# ip address 192.168.1.1 255.255.255.128 Router(config-if)# no shutdownOn a /30 router-to-router link, one end takes
.241 and the other .242.show ip interface brief (every interface up with the right address), show ip route (each connected route with its own prefix length) and a ping from every PC to its gateway.Most lab mistakes are a mask typed on the router that does not match the plan. The VLSM solver prints the whole table for any set of requirements, so you can check your paper version before you start typing.
IPv6 does not need VLSM to save addresses. Every LAN is a /64 however many hosts it has, router-to-router links can use a /127 (RFC 6164) and loopbacks a /128. Planning still happens, but it is about hierarchy: a site gets a /48, each building a /56 or /60, each VLAN a /64, ideally on 4-bit boundaries so prefixes stay readable in hex. The IPv6 guide covers the notation.
VLSM (Variable Length Subnet Masking) is subnetting one address block into subnets of different sizes, each with its own mask, so every segment gets roughly the number of addresses it needs instead of one fixed size for all.
For each segment add 2 to the required hosts and round up to the next power of two; that block size gives the prefix (32 minus the number of host bits). Sort the segments from largest to smallest and assign each block at the next free address, which is then automatically aligned.
FLSM (Fixed Length Subnet Masking) uses the same mask for every subnet, which is simple but wastes addresses on small segments. VLSM uses a different mask per subnet, which saves space but needs planning and a classless routing protocol.
VLSM is about dividing a block you own into subnets of different sizes. CIDR is the classless addressing scheme behind it, used to allocate and aggregate blocks of any prefix length, for example summarising several routes into one shorter prefix. VLSM goes down from a block, CIDR summarisation goes up.
Yes. OSPF is a classless routing protocol: it carries the prefix length with every route, so subnets of different sizes are advertised correctly. RIPv2, EIGRP, IS-IS and BGP support VLSM too; RIPv1 and IGRP do not.
Every block must start at a multiple of its own size. Placing the largest blocks first means each smaller block lands on a boundary that is already aligned, so the plan has no gaps and no overlaps.