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.

The 256 addresses of 192.168.10.0/24 as one bar. From the left: Sales /25 (.0 to .127, 128 addresses), Eng /26 (.128 to .191, 64), HR /27 (.192 to .223, 32), IT /28 (.224 to .239, 16), WAN1 /30 (.240), WAN2 /30 (.244), and free .248 to .255 (8 addresses).
Largest first: six subnets of five sizes, packed with no gap, 8 addresses left over.

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.

SubnetHostsHosts + 2BlockPrefixUsableUnused
Sales100102128 = 27/2512626
Eng505264 = 26/266212
HR252732 = 25/27305
IT101216 = 24/28144
WAN1, WAN2244 = 22/3020

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.

Two bars of 256 addresses. Top, largest first: Sales .0/25, Eng .128/26, HR .192/27, IT .224/28, two /30 links, free .248 to .255, all six fit. Bottom, in request order: HR .0/27, a 96-address gap from .32 to .127, Sales .128/25; Eng, IT, WAN1 and WAN2 do not fit.
Same six requests: sorted, they fit; in request order, Sales must jump to .128 and four subnets are left out.

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.

SubnetNetworkMaskGatewayLast hostBroadcast
Sales192.168.10.0/25255.255.255.128.1.126.127
Eng192.168.10.128/26255.255.255.192.129.190.191
HR192.168.10.192/27255.255.255.224.193.222.223
IT192.168.10.224/28255.255.255.240.225.238.239
WAN1192.168.10.240/30255.255.255.252.241.242.243
WAN2192.168.10.244/30255.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.

MethodSubnetsUsable eachResult
fixed /27830Sales (100) and Eng (50) are too small; the two links waste 28 addresses each (Demo 3)
fixed /252126Sales and Eng fit, HR, IT and both links get nothing; Eng alone leaves 76 unused (Demo 4)
VLSM6126 … 2all 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)

The last byte of each network in binary: Sales .0 = 00000000, Eng .128 = 10000000, HR .192 = 11000000, IT .224 = 11100000, WAN1 .240 = 11110000, WAN2 .244 = 11110100. The five lower rows all start with 1, so they summarise to 192.168.10.128/25. With Sales the first bit differs, so the summary is 192.168.10.0/24.
Keep the leading bits every network shares: the five small subnets collapse to one /25, all six to the /24.

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.

On the mind map

Open the Networking mind mapNetworkingLayers & links: frames on one local networkLayers & linksIP & routing: packets hop between networksIP & routingCore services: address, name and timeCore servicesTCP, UDP & sockets: end to end between two portsTCP, UDP & socketsHTTP & TLS: what a browser does per requestHTTP & TLSAPIs & push: how apps talk to serversAPIs & pushProxies & edge: boxes in the middle of the pathProxies & edgeContainers: virtual networks from Linux partsContainersReal-time media: voice and video over UDPReal-time mediaSecurity at the edge: filter traffic at the borderSecurity at the edgeRouter forwardingRouter forwardinglongest prefix match picks the next hopVRRP / HSRP failoverVRRP / HSRP failoverBackup takes over the gateway in 3.6 sSDN and OpenFlowSDN and OpenFlowcontroller writes rules, switch looks upTracerouteTracerouteTTL 1, 2, 3: each hop sends Time ExceededNATNATmaps private IP:port to one public IPIPv4 vs IPv6IPv4 vs IPv632 vs 128 bits; SLAAC, no NAT neededAnycast and BGPAnycast and BGPsame prefix announced from many sitesOSPF and BGP policyOSPF and BGP policyPolicy first, then path, then IGP costDistance vector vs link stateDistance vector vs link stateRIP shares distances; OSPF floods the mapSubnets and CIDRSubnets and CIDR/24 = mask: same subnet? ARP, else routerVLSM PlanningLargest first: no gaps, one summary routeRouter queues and AQMRouter queues and AQMFull buffers add delay; drop earlyDelay, loss, throughputDelay, loss, throughputSlowest link sets pace; full buffer dropsOpen the Networking mind mapNetworkingpackets hop between networksIP & routingRouter forwardingRouter forwardinglongest prefix match picks the next hopVRRP / HSRP failoverVRRP / HSRP failoverBackup takes over the gateway in 3.6 sSDN and OpenFlowSDN and OpenFlowcontroller writes rules, switch looks upTracerouteTracerouteTTL 1, 2, 3: each hop sends Time ExceededNATNATmaps private IP:port to one public IPIPv4 vs IPv6IPv4 vs IPv632 vs 128 bits; SLAAC, no NAT neededAnycast and BGPAnycast and BGPsame prefix announced from many sitesOSPF and BGP policyOSPF and BGP policyPolicy first, then path, then IGP costDistance vector vs link stateDistance vector vs link stateRIP shares distances; OSPF floods the mapSubnets and CIDRSubnets and CIDR/24 = mask: same subnet? ARP, else routerVLSM PlanningLargest first: no gaps, one summary routeRouter queues and AQMRouter queues and AQMFull buffers add delay; drop earlyDelay, loss, throughputDelay, loss, throughputSlowest link sets pace; full buffer drops
This page on the Networking mind map · 62 pages in 10 branches · open it to see the whole map and test yourself in recall mode.