The idea: one block, subnets of different sizes
A site gets one address block, here 192.168.10.0/24: 256 addresses. Its departments are not the
same size. Sales has 100 machines, HR has 25, and a link between two routers has just 2. If every subnet used the
same mask, the big ones would not fit or the small ones would waste most of their space.
VLSM (Variable Length Subnet Masking) gives each subnet its own prefix length, sized to what it
needs. The page plans six subnets inside the one /24.
This page is about planning many subnets. What a mask is, and how a host uses it to decide "same subnet or router", is on Subnets and CIDR.
Sizing a subnet
A subnet with b host bits has 2b addresses. Two of them are reserved: the network address (host bits all 0) and the broadcast address (host bits all 1). So a subnet for h hosts needs h + 2 addresses, rounded up to a power of two. The prefix is 32 − b.
| Subnet | Hosts | Hosts + 2 | Block | Prefix | Usable | Unused |
|---|---|---|---|---|---|---|
| Sales | 100 | 102 | 128 = 27 | /25 | 126 | 26 |
| Eng | 50 | 52 | 64 = 26 | /26 | 62 | 12 |
| HR | 25 | 27 | 32 = 25 | /27 | 30 | 5 |
| IT | 10 | 12 | 16 = 24 | /28 | 14 | 4 |
| WAN1, WAN2 | 2 | 4 | 4 = 22 | /30 | 2 | 0 |
The edge cases matter. 62 hosts fit a /26 exactly; 63 hosts need 65 addresses, which is a
/25 of 128. (Demo 5: Eng grows to 63 hosts) A router-to-router link uses a
/30: two router addresses and nothing to spare.
A block starts at a multiple of its size
The network address has all host bits 0. For a /25 that means the last 7 bits are 0, so a
/25 can only start at .0 or .128. A /26 starts at a multiple
of 64, a /27 at a multiple of 32, and so on. 192.168.10.32/25 is not a valid network.
Largest first
The planner keeps a pointer to the next free address and hands out blocks one after another. Sorted largest first, every block starts exactly where the last one ended: each size divides the size before it, so the pointer is always on a valid boundary. No gap ever opens. (Demo 1: Largest first)
In request order, HR (/27) takes .0–.31. Sales then needs a /25, which
cannot start at .32, so it jumps to .128. The 96 addresses .32–.127 are
left behind, and Eng, IT and both links find no room after .255.
(Demo 2: As listed) A careful person could go back and fill the gap, but sorting first means there is
never a gap to fill.
The plan: network, gateway, broadcast
For each subnet the plan lists the network and mask, the range of host addresses and the broadcast address. The gateway (the router's interface on that subnet) is by convention the first host address; the last one works just as well, as long as the whole site follows one rule.
| Subnet | Network | Mask | Gateway | Last host | Broadcast |
|---|---|---|---|---|---|
| Sales | 192.168.10.0/25 | 255.255.255.128 | .1 | .126 | .127 |
| Eng | 192.168.10.128/26 | 255.255.255.192 | .129 | .190 | .191 |
| HR | 192.168.10.192/27 | 255.255.255.224 | .193 | .222 | .223 |
| IT | 192.168.10.224/28 | 255.255.255.240 | .225 | .238 | .239 |
| WAN1 | 192.168.10.240/30 | 255.255.255.252 | .241 | .242 | .243 |
| WAN2 | 192.168.10.244/30 | 255.255.255.252 | .245 | .246 | .247 |
The plan uses 248 of the 256 addresses. Inside the subnets, 47 host addresses are unused (room to grow), and
.248–.255, a /29, is still free for one more small subnet.
VLSM against one fixed mask
With one mask for everything, the mask has to suit either the biggest subnet or the number of subnets. It can't do both here.
| Method | Subnets | Usable each | Result |
|---|---|---|---|
fixed /27 | 8 | 30 | Sales (100) and Eng (50) are too small; the two links waste 28 addresses each (Demo 3) |
fixed /25 | 2 | 126 | Sales and Eng fit, HR, IT and both links get nothing; Eng alone leaves 76 unused (Demo 4) |
| VLSM | 6 | 126 … 2 | all fit; 47 unused inside subnets, 8 free (Demo 1) |
To give all six a /25, the site would need 768 addresses, three /24s. VLSM fits the
same needs into one.
Route summarisation
Routers elsewhere need a route to every subnet. Because the plan is one contiguous block, they don't need six:
the edge router can advertise a single summary (also called an aggregate or supernet). Write the
last byte of each network in binary and keep the bits they all share. The five smaller subnets all start with a
1 bit, .128 = 10000000 to .244 = 11110100, so they share 25
bits: 192.168.10.128/25. Add Sales (.0 = 00000000) and only the 24 bits of
192.168.10 are shared: one route 192.168.10.0/24. (Demo 6: Route summary)
A summary can cover addresses that no subnet uses. 192.168.10.128/25 also covers the free
.248–.255, so packets sent there reach the edge router and are dropped. Summaries only work when
related subnets sit next to each other, which is one more reason to plan the block in one go. Which route a
router picks when a summary and a longer prefix both match is the longest prefix match on
How a Router Forwards a Packet.
See also Subnets and CIDR for masks and the same-subnet test,
DHCP, which hands out an address, mask and gateway from each subnet's range, and
NAT, which lets a private block like 192.168.10.0/24 reach the Internet.
See also OSPF Inside, BGP Between for how routers inside and between networks learn and choose routes to prefixes like these.
What the page leaves out
Back-filling gaps after an unsorted plan, /31 point-to-point links with no network or broadcast
address (RFC 3021), growth reserves per department, plans that span several blocks, IPv6 (where a LAN is almost
always a /64, so sizing is not an issue), and the routing protocols that carry the summary between
routers.