MarzleyTech Learn

Home / Learn / Networking / VLSM: different subnet sizes in one network, step by step with full worked designs

VLSM: different subnet sizes in one network, step by step with full worked designs

Giving every subnet the same size wastes addresses: a router-to-router link with 2 devices doesn't need 30 addresses, and a 10-person office doesn't need 254. VLSM (Variable Length Subnet Masking) lets you use different prefixes for different subnets inside one block, so each gets just what it needs. With public IPv4 addresses scarce and expensive, and private ranges needing careful planning in big organisations and clouds, VLSM is an everyday skill and a guaranteed exam topic.

Fixed-size vs VLSM

Requirements: Sales 100 hosts, Admin 50, IT 20, Guests 10, two router links of 2.

  • Fixed size: the largest need (100) requires a /25. Six /25 subnets = 768 addresses = three /24s, most of it wasted.
  • VLSM: everything fits into one /24, with space to spare.

The method

  1. List every requirement and sort from largest to smallest.
  2. For each, pick the smallest block that fits: hosts + 2 ≤ block size (block sizes are powers of 2).
  3. Allocate them one after another, starting at the beginning of the block. Each new subnet starts right after the previous broadcast.
  4. Record network, prefix, mask, usable range and broadcast.
  5. Verify: no overlaps, every subnet starts on a multiple of its own block size.

Going largest first guarantees every subnet lands on a correct boundary.

Choosing the prefix

Hosts neededBlockPrefixMask
1–24/30255.255.255.252
3–68/29255.255.255.248
7–1416/28255.255.255.240
15–3032/27255.255.255.224
31–6264/26255.255.255.192
63–126128/25255.255.255.128
127–254256/24255.255.255.0
255–510512/23255.255.254.0

Note the edges: 62 hosts fit a /26, but 63 need a /25; 30 fit a /27, 31 need a /26.

Example 1: one office block

You have 192.168.10.0/24 and need:

NeedHostsBlock that fitsPrefixSubnetUsable rangeBroadcast
Sales100128/25192.168.10.0/25.1 – .126.127
Admin5064/26192.168.10.128/26.129 – .190.191
IT2032/27192.168.10.192/27.193 – .222.223
Guests1016/28192.168.10.224/28.225 – .238.239
Link 124/30192.168.10.240/30.241 – .242.243
Link 224/30192.168.10.244/30.245 – .246.247
Free192.168.10.248/29

Everything fits in one /24 with a /29 spare.

Python · runs live in the interactive lesson
import ipaddress, math

def vlsm(block, needs):
    free = int(ipaddress.ip_network(block).network_address)
    for name, hosts in sorted(needs, key=lambda n: -n[1]):
        size = 2 ** math.ceil(math.log2(hosts + 2))
        prefix = 32 - int(math.log2(size))
        net = ipaddress.ip_network(f"{ipaddress.ip_address(free)}/{prefix}")
        print(f"{name:7} {hosts:4} hosts -> {str(net):18} usable {net[1]} - {net[-2]}  bcast {net.broadcast_address}")
        free += size

vlsm("192.168.10.0/24", [("Guests", 10), ("Sales", 100), ("Link1", 2), ("IT", 20), ("Admin", 50), ("Link2", 2)])

Example 2: a company WAN

A company has 172.16.0.0/22 (1,024 addresses) for its head office and branches:

SiteHosts
Nairobi HQ300
Mombasa120
Kisumu60
Eldoret25
3 WAN links (HQ to each branch)2 each

Sorted and allocated:

SiteHostsBlockSubnetUsable rangeBroadcast
Nairobi HQ300512172.16.0.0/23172.16.0.1 – 172.16.1.254172.16.1.255
Mombasa120128172.16.2.0/25172.16.2.1 – .126172.16.2.127
Kisumu6064172.16.2.128/26.129 – .190172.16.2.191
Eldoret2532172.16.2.192/27.193 – .222172.16.2.223
WAN 124172.16.2.224/30.225 – .226.227
WAN 224172.16.2.228/30.229 – .230.231
WAN 324172.16.2.232/30.233 – .234.235
Free172.16.2.236 onwards and all of 172.16.3.0/24

Modern designs often use /31 for point-to-point links (2 addresses, both usable), saving even more.

Checking your design

  • Boundaries: a /26 must start at a multiple of 64 (.0, .64, .128, .192); a /23 must start at an even third octet.
  • No overlaps: each subnet's network address must be greater than the previous broadcast.
  • Use the calculator below to verify each line.

This part of the lesson has an interactive tool. Open the live lesson to use it.

Common mistakes

  • Not sorting largest first: putting a /30 first at .0 forces the next /25 to start at .128, wasting .4–.127.
  • Forgetting the 2 reserved addresses: 62 hosts → /26, but 63 → /25.
  • Overlapping subnets: e.g. allocating 192.168.10.192/26 after 192.168.10.128/25 (the /25 already covers .128–.255).
  • Not leaving room: allocate in order, but keep free space at the end for growth.

VLSM and routing

VLSM requires classless routing protocols that send the prefix length with each route: OSPF, EIGRP, IS-IS, BGP and RIPv2. Old RIPv1 didn't send masks and couldn't support VLSM. Static routes always include the mask, so they're fine.

Think about it: You must add a new site with 70 hosts to Example 1 (192.168.10.0/24). Is there room?Show answer

No. 70 hosts need a /25 (128 addresses), but only a /29 (8 addresses) is free. You'd need another block, or to redesign (e.g. if Sales could move to a different block).

Summary

  • VLSM uses different prefixes inside one block so each subnet gets just enough addresses.
  • Method: sort largest first, pick the smallest block with hosts + 2 ≤ size, allocate consecutively, record and verify.
  • Watch the edges: 62 → /26 but 63 → /25.
  • Every subnet must start on a multiple of its block size, with no overlaps.
  • VLSM needs classless routing (OSPF, EIGRP, BGP, RIPv2, static routes).

Check yourself

  1. A subnet needs 60 hosts. Which prefix is the smallest that fits?

    Show answer

    /26

  2. A subnet needs 64 hosts. Which prefix?

    Show answer

    /25 · A /26 has only 62 usable addresses.

  3. For a point-to-point router link (2 hosts, not using /31), which prefix?

    Show answer

    /30

  4. In the table, what is the network address of the Guests subnet?

    Show answer

    192.168.10.224

  5. In VLSM, do you allocate largest or smallest subnets first?

    Show answer

    largest

  6. Which old routing protocol could NOT support VLSM?

    Show answer

    RIPv1

Lesson 10 of 24 in Networking · Written by · Course notes