CIDR, VLSM and Subnet Design

VLSM means using more than one subnet mask inside one classful network, such as /24 on the LANs and /30 on point-to-point links. It needs a classless routing protocol, one that advertises the mask with every route, and a design whose subnets never overlap.

In Daveth Pro (Network)19 min video

By , founder of Daveth · Updated

Opening frame of the video walkthrough of CIDR, VLSM and Subnet Design

Watch this lesson

19 min · Video walkthrough

In Daveth Pro (Network)

The full 19 min walkthrough is in Daveth Pro (Network). See what the plan opens

What this page answers

What is VLSM (variable-length subnet masking)?

A subnet design that uses more than one mask for different subnets of a single Class A, B or C network. One mask for every subnet of 10.0.0.0 and another for every subnet of 11.0.0.0 is not VLSM. Read it in “VLSM: more than one mask in one network”

Why does VLSM need a classless routing protocol?

Without the mask, a router that learns 10.1.8.0 cannot tell a /24 from a /23 or a /30. Classless protocols such as OSPF advertise the mask with every route; classful ones do not. Read it in “What the routers need: the mask, and nothing else”

What is CIDR (classless inter-domain routing)?

CIDR, defined in RFC 4632, is the convention for how IANA, the registries and ISPs assign public IPv4 addresses: blocks sized to what an organisation needs instead of whole Class A, B or C networks, and routes that aggregate them. Read it in the lesson

One mask, or the right mask?

Thursday. The branch's WAN link is on order, and Maya is adding it to the plan. With 04.1's one mask for every subnet, the link gets a /24: 254 host addresses for two routers. The office's link to head office, R1 to R3, already has a /24 of its own. 04.1 chose one mask for simplicity and said the alternative was several masks in one network. Today Maya takes a proper look at it.

Two routers, 254 addresses. The link has more spare seats than the office has chairs.

VLSM: more than one mask in one network

Variable-length subnet masks (VLSM) means a subnet design that uses more than one mask for different subnets of a single Class A, B or C network. A typical design uses /24 (255.255.255.0) on the LAN subnets and /30 (255.255.255.252) on point-to-point serial links, with every subnet in Class A network 10.0.0.0: two masks, one classful network, so it's VLSM.

A common mistake is to think VLSM means "more than one mask somewhere in the internetwork". It's more than one mask in the same classful network. So a network where every subnet of 10.0.0.0 uses one mask and every subnet of 11.0.0.0 uses another doesn't use VLSM at all.

Because a mask sets the size of a subnet, VLSM lets the size match the need: a subnet that needs fewer addresses gets a mask with fewer host bits, so fewer addresses are wasted, and more space is left for more subnets. The savings matter most with public addresses, where they can save an organisation from having to get another registered network. With private networks (RFC 1918, 04.1) running out matters less, because another private network is always there to take.

Maya's plan uses the private network 10.0.0.0, and 04.1 was right that the waste rarely matters there: the addresses saved are a small bonus. What Maya wants is order. The LANs keep /24, because the plan's split (routers and servers at .1 to .100, DHCP at .101 to .254) needs a /24. Every WAN link takes a /30 from one /24 kept for links, 10.255.255.0/24, so any address beginning 10.255.255 is a link: 04.1's LAN subnets low, WAN subnets high. The R1-R3 link moves to the first /30 one quiet evening, and the branch's link takes the next. That's VLSM:

SubnetsPrefixMaskHosts per subnet
Every LAN (office, head office, the branch)/24255.255.255.0254
Every WAN link, from 10.255.255.0/24/30255.255.255.2522
LinkSubnetUsable addressesBroadcast
R1 to R3 (office to head office)10.255.255.0/3010.255.255.1 – 10.255.255.210.255.255.3
The branch's link (next month)10.255.255.4/3010.255.255.5 – 10.255.255.610.255.255.7

What the routers need: the mask, and nothing else

Before a VLSM design can work, the routing protocol has to support it, and that means it must advertise the mask with each subnet. Without the mask, a router that learns a route for 10.1.8.0 can't tell whether that's 10.1.8.0/24, 10.1.8.0/23 or 10.1.8.0/30: the same number is a valid subnet ID for several masks, and with VLSM any of them might be in use.

Classless routing protocols advertise the mask with every route; classful ones don't. The classless protocols are the newer, more capable ones, and as well as VLSM they support manual route summarization: advertising one route for a larger range instead of many routes for the small subnets inside it. OSPF, the routing protocol this course uses, is classless. There's no command to make a protocol include masks; the only choice is to use a classless one.

And the routers themselves need no VLSM configuration. Nothing turns it on or off. VLSM simply happens when interfaces in the same classful network are given addresses with different masks, R1's LAN interface with a /24 and its WAN interface with a /30, for example. A router's routing table shows it: the routes are grouped by classful network, and the heading for 10.0.0.0 says it's "variably subnetted", with the number of subnets and masks. That count includes a /32 route the router adds for each of its own interface addresses, so a design of /24s and /30s shows 3 masks.

Designing without overlaps

With one mask, every subnet came from one neat list, and two subnets could only collide by having the same subnet ID. With several masks, you have to choose each subnet more carefully. First, each subnet ID must be a valid subnet ID for its own mask: its host part, in binary, all 0s (04.3). A /24 in Class B network 172.16.0.0 can be 172.16.0.0, 172.16.1.0, 172.16.2.0 and so on up to 172.16.255.0, exactly the IDs you'd get by subnetting the whole network with that one mask; a /23 can only start on an even third octet.

Second, subnets must never overlap, VLSM or not. Two subnets overlap when their ranges share any address. Then routers' routing entries overlap, the same address can be given to hosts in two places, and packets can't be routed correctly: some hosts simply can't talk outside their subnets. A design with overlapping subnets is an incorrect design.

Without VLSM, overlapping subnets have the same subnet ID, so they're easy to spot. With VLSM they may not: 172.16.0.0/22 runs from 172.16.0.0 to 172.16.3.255, so it contains 172.16.3.0/24, a different number. Choosing one subnet rules out every candidate, of any size, whose range shares an address with it. So compare whole ranges, subnet ID to broadcast, never just the subnet IDs. In 172.16.0.0, for instance, 172.16.4.0/22 runs from 172.16.4.0 to 172.16.7.255, so it holds 172.16.4.0/23, 172.16.6.0/23 and every /24 from 172.16.4.0 to 172.16.7.0. And once 172.16.3.0/24 is in use, both 172.16.2.0/23 and 172.16.0.0/22 are ruled out.

You can think of it as rooms in a building: two rooms with different numbers on the plan can still be drawn over the same floor space, and that's the overlap. (Where it stops: rooms can't sit inside each other, but a large subnet can hold several small ones entirely, as the /22 holds the /24.)

To size each subnet, find the longest prefix (the biggest /number, so the smallest subnet, with H = 32 − the prefix) whose 2^H − 2 still covers the addresses needed, router interfaces included. Then place them. One habit keeps the boundaries easy: place the largest first, each at the next address that's a valid boundary for its own size: a multiple of its block size, 04.4's magic number, in the interesting octet. So a /25 starts at .0 or .128, a /26 on a multiple of 64 and a /30 on a multiple of 4. A college given 10.20.0.0/22 needs subnets for 180, 70 and 40 addresses (Staff, Lab and Guest, routers included) and a two-router link:

180 needs a /24 (254), 70 a /25 (126), 40 a /26 (62), and the link a /30 (2). Placed largest first: Staff 10.20.0.0/24, then Lab 10.20.1.0/25, Guest 10.20.1.128/26 and the link 10.20.1.192/30. Each starts on a boundary for its own size, and no two ranges share an address. Guest's router will probably take the first usable address, .129, so it's tempting to think the subnet starts at .130. It doesn't: 10.20.1.130 isn't a /26 subnet ID, it's a host inside 10.20.1.128/26.

To check a finished design for overlaps, three steps: work out each subnet's ID and broadcast; list them in order of subnet ID; then compare each pair of neighbours in the list to see whether their ranges overlap. When two neighbours overlap, compare the next entry with both of them, because one big subnet can contain several: 10.1.0.0/16 contains both 10.1.200.0/24 and 10.1.250.0/24, though those two don't overlap each other.

An overlap doesn't always announce itself. A question may just say that some hosts can't ping each other. Say Site B's LAN is 172.16.4.1/23 and Site C's is 172.16.5.1/24: the subnet IDs, 172.16.4.0 and 172.16.5.0, differ, but Site B's range runs to 172.16.5.255 and so contains all of Site C's. The design is invalid, and one of the two subnets has to change.

The ledger below does the college's allocation for any block and host counts, draws the block to scale, and checks a proposed extra subnet against the plan. The proposal box starts with a tempting 10.20.1.128/25 for a second lab:

Interactive tool: The allocation ledger Block 10.20.0.0/22 Addresses needed, routers included: Staff 180 Lab 70 Guest 40 Router link 2 10.20.0.0/22, largest first Need Addresses needed Prefix Subnet ID Broadcast Usable Staff 180 /24 (254) 10.20.0.0 10.20.0.255 10.20.0.1 – 10.20.0.254 Lab 70 /25 (126) 10.20.1.0 10.20.1.127 10.20.1.1 – 10.20.1.126 Guest 40 /26 (62) 10.20.1.128 10.20.1.191 10.20.1.12