Skip to content

Beginner · Subnetting practice and IPv6 · topic 17 of 57 · 35 min

VLSM: subnets of different sizes

Explanation

VLSM (Variable Length Subnet Masking) lets you cut one block into subnets of different sizes, so a 100-host lab, a 25-host office and a 2-host router link each get just what they need. Allocate the largest subnet first, then the next largest, each starting right after the previous one. This keeps every subnet on a valid boundary and leaves the free space in one tidy piece.

Why equal subnets waste addresses

With equal subnets, every subnet has the size of the biggest one. If your largest group needs 100 hosts, every subnet becomes a /25 with 126 hosts. A link between two routers needs only 2 addresses, so a /25 on that link wastes 124. A /24 holds only two /25s, so you run out after two groups.

VLSM, Variable Length Subnet Masking, means using different prefix lengths inside the same block. Big groups get big subnets, small groups get small ones. All modern routing protocols (OSPF, EIGRP, BGP, RIP version 2) send the mask with each route, so VLSM works everywhere today.

Think of it like this: VLSM is like packing a suitcase. You put the big things in first, the laptop and the shoes, then fit the smaller things into the gaps. If you start with the socks, the laptop no longer fits even though there is enough space in total.

The largest-first method

  1. List every group and how many hosts it needs. Count the router's gateway address as a host, and add room to grow.
  2. Sort the list from the largest to the smallest.
  3. For each group, pick the smallest prefix where 2^h − 2 is at least the host count.
  4. Give the first group the start of the block. Give each next group the address right after the previous broadcast address.
  5. Write down network, mask, host range and broadcast for each, and keep the leftover space as one or more free blocks.

Why largest first? A subnet must start at a multiple of its own block size: a /26 starts at 0, 64, 128 or 192. If you go from largest to smallest, the next free address is always a multiple of the next block size, so the subnets line up with no gaps and no overlap.

A full worked plan: an engineering college in Pune

The college has 192.168.10.0/24 for its new academic block. It needs: computer labs 100 hosts, staff 50 hosts, administration 25 hosts, and two point-to-point links to other buildings, 2 hosts each.

  1. Labs, 100 hosts: 2^7 − 2 = 126 is enough, so /25. Start at the beginning: 192.168.10.0/25, hosts .1 to .126, broadcast .127.
  2. Staff, 50 hosts: 2^6 − 2 = 62, so /26. Next free address is .128: 192.168.10.128/26, hosts .129 to .190, broadcast .191.
  3. Admin, 25 hosts: 2^5 − 2 = 30, so /27. Next free is .192: 192.168.10.192/27, hosts .193 to .222, broadcast .223.
  4. Link 1, 2 hosts: /30. Next free is .224: 192.168.10.224/30, hosts .225 and .226, broadcast .227.
  5. Link 2, 2 hosts: /30. Next free is .228: 192.168.10.228/30, hosts .229 and .230, broadcast .231.
GroupHosts neededPrefix (usable)NetworkHost rangeBroadcast
Labs100/25 (126)192.168.10.0.1 to .126.127
Staff50/26 (62)192.168.10.128.129 to .190.191
Admin25/27 (30)192.168.10.192.193 to .222.223
Link 12/30 (2)192.168.10.224.225 to .226.227
Link 22/30 (2)192.168.10.228.229 to .230.231
Freelater use/29 and /28192.168.10.232/29, 192.168.10.240/28

Everything fits in one /24 with 24 addresses to spare. With equal /25 subnets, the same needs would not have fitted at all.

python
import ipaddress

plan = ["192.168.10.0/25", "192.168.10.128/26", "192.168.10.192/27", "192.168.10.224/30", "192.168.10.228/30"]
nets = [ipaddress.ip_network(p) for p in plan]
for a in nets:
    for b in nets:
        if a != b and a.overlaps(b):
            print("overlap:", a, b)
print("checked", len(nets), "subnets")
A quick overlap check for any plan. overlaps() is True if two networks share any address.

Common mistakes

Careful: Overlapping subnets. If labs get 192.168.10.0/25 and someone later gives staff 192.168.10.96/27, both claim .96 to .127. Routers then send traffic to the wrong place and the fault looks random. Keep the plan in one shared document and check new subnets against it.
  • Starting a subnet on a wrong boundary, such as 192.168.10.200/26. A /26 must start at 0, 64, 128 or 192.
  • Forgetting the gateway: a group of 30 PCs plus the router needs 31 addresses, so a /27 (30) is too small.
  • No room to grow: the lab with 100 PCs may have 130 next year. Leave spare space where you can.
  • Going smallest first, which leaves gaps and breaks the alignment of later, bigger subnets.
Tip: For router-to-router links, a /30 is the classic CCNA answer. Many networks now use /31 links (RFC 3021) to save even more addresses.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

VLSM: subnets of different sizes · 1/7

VLSM

Equal subnets waste addresses, because every subnet gets the size of the biggest one. VLSM fixes this.

Prefer a video by a teacher? Find free videos on “vlsm subnetting step by step example ccna” on YouTube ↗

In real life: A hospital chain adds a new branch

A hospital chain in Hyderabad gives each new branch a 10.40.x.0/24 from its master plan. The network engineer for the Kukatpally branch has wards (90 devices), OPD and pharmacy (40), doctors' offices (20), CCTV (12) and one WAN link. Largest first, she gets a /25, a /26, a /27, a /28 and a /30, all inside the branch /24, with space left for the medical devices that are coming next year. She uses a small script to print the plan and pastes it into the change request.

python
import ipaddress

needs = [("wards", 25), ("opd", 26), ("doctors", 27), ("cctv", 28), ("wan", 30)]
start = ipaddress.ip_address("10.40.7.0")
for name, prefix in needs:
    net = ipaddress.ip_network(f"{start}/{prefix}")
    print(name, net)
    start = net.broadcast_address + 1
Shows wards 10.40.7.0/25, opd .128/26, doctors .192/27, cctv .224/28, wan .240/30.

Practice (0/3 done)

Task 1 · Code · Python

Write fits(hosts, prefix) that returns True when a subnet with that prefix has enough USABLE addresses for the hosts (2 ** (32 - prefix) - 2 >= hosts).

Task 2 · Code · Python

Build a VLSM allocator. vlsm(base, host_counts) sorts the host counts from largest to smallest, gives each the smallest subnet that fits (prefix_for is written for you), allocates them one after another from the start of base, and returns the list of subnets as strings in that order. If a subnet would go outside base, raise ValueError. Tip: ipaddress.ip_network((number, prefix)) builds a network from an integer address and a prefix, and net.subnet_of(base_net) tells you if it is inside.

Task 3 · Practice

Design a VLSM plan for a hospital branch in Lucknow that has 10.20.0.0/22. Needs: wards 300 hosts, OPD 120, labs 60, admin 28, and two router links of 2 hosts each. For each group give the network with prefix, the mask, the host range and the broadcast. List the free space left over.

Quick quiz

Question 1

1.In VLSM, why do you allocate the largest subnet first?

Question 2

2.Which prefix should a link between two routers get in a classic CCNA VLSM plan?

Question 3

3.A group has 30 PCs plus the router gateway. Which is the smallest prefix that fits?

Question 4

4.Which of these is NOT a valid start for a /26 subnet?

Question 5

5.After 192.168.10.0/25 and 192.168.10.128/26 are used, where does the next subnet start?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

In VLSM, why do you allocate the largest subnet first?

Answer: It keeps each subnet on a valid boundary with no gaps or overlaps

Going largest first means the next free address is always a multiple of the next, smaller block size.

Which prefix should a link between two routers get in a classic CCNA VLSM plan?

Answer: /30

A /30 has exactly 2 usable addresses, one for each router. (/31 is also possible under RFC 3021.)

A group has 30 PCs plus the router gateway. Which is the smallest prefix that fits?

Answer: /26

31 addresses are needed. A /27 has only 30 usable, so you need a /26 (62).

Which of these is NOT a valid start for a /26 subnet?

Answer: 192.168.10.160

A /26 has a block size of 64, so it starts at 0, 64, 128 or 192. 160 is not a multiple of 64.

After 192.168.10.0/25 and 192.168.10.128/26 are used, where does the next subnet start?

Answer: 192.168.10.192

The /26 ends at broadcast 192.168.10.191, so the next free address is 192.168.10.192.

Each subnet must hold 25 hosts. Which prefix wastes the fewest addresses?Related

Answer: /27

/27 gives 30 usable hosts. /28 gives only 14, and /26 wastes more.

From Subnetting a network into equal subnets

Where does Cisco IOS expect a wildcard mask instead of a subnet mask?Related

Answer: In access-list statements and the OSPF network command

Interfaces take subnet masks. ACLs and OSPF network statements take wildcard masks.

From Subnet masks, prefix length and wildcard masks

Are 10.1.1.100/25 and 10.1.1.130/25 in the same subnet?Related

Answer: No

/25 splits the octet at 128. 100 is in 0 to 127, 130 is in 128 to 255, so they are in different subnets.

From Validating addresses and checking the same subnet

Is 192.168.0.255/23 a usable host address?Related

Answer: Yes, the subnet runs from 192.168.0.0 to 192.168.1.255

In a /23 the broadcast is 192.168.1.255. 192.168.0.255 is in the middle of the range, so it is a normal host.

From Network, broadcast and usable host range

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “Subnetting practice and IPv6” before its exam: Subnetting drills for exam speed, IPv6 addresses: format and shortening rules, IPv6 address types, EUI-64, SLAAC and NDP.
  2. Module 4 exam: Subnetting practice and IPv6 · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Switching and VLANs. 57 topics left in the course before the final exam.

← Previous: Subnetting a network into equal subnets