Showing raw Markdown: the renderer could not load.
## Why this matters
Your company has just opened a branch office. Someone gave it `192.168.10.0/24` and put every device on it: staff laptops, the guest Wi-Fi, IP phones, printers and the switches' management interfaces. Six months later, a guest's infected laptop scans the printers, the phones suffer from broadcast noise, and the firewall can't tell staff traffic from guest traffic because they share one range.
The fix is not more address space. It is a plan: split the block into several smaller networks, one per purpose, each sized to what it really needs. That is **subnetting**. You'll use it every time you create a virtual LAN (VLAN), a cloud virtual private cloud (VPC) or a site-to-site virtual private network (VPN). If you get it wrong, you'll see it later as overlapping ranges, unreachable hosts and late-night tickets.
## Learning objectives
- Calculate equal-size subnets (Fixed-Length Subnet Masking, FLSM) from an address block, given a required number of subnets or hosts per subnet.
- Design an addressing plan with Variable-Length Subnet Masking (VLSM) that meets the requirements without overlapping or wasting address space.
- Summarize contiguous networks into a single aggregate route (supernetting) and explain when aggregation is possible.
- Troubleshoot common addressing faults: wrong subnet mask, overlapping subnets and a default gateway outside the host's subnet.
## Key concepts
> [!NOTE]
> This lesson builds on [05 — IP Addressing](../05-ip-addressing/README.md). Quick recap: an IPv4 address has 32 bits. The **prefix length** (`/24`) says how many leading bits identify the network; the rest identify the host. In each network, the lowest address (all host bits 0) is the network address and the highest (all host bits 1) is the broadcast address. Usable hosts = 2<sup>host bits</sup> − 2. IPv6 subnetting is covered in [07 — IPv6](../07-ipv6/README.md).
### Why subnet?
Think of an open-plan office with 500 people. Every announcement shouted in the room reaches everyone, anyone can walk to any desk, and finding someone means shouting their name. Walls, doors and a reception desk fix that. Subnets are the walls, and routers and firewalls are the doors.
A **subnet** is a smaller network carved out of a larger address block by using a longer prefix. Splitting a block brings four practical benefits:
| Benefit | What it means in practice |
|---|---|
| Smaller broadcast domains | Address Resolution Protocol (ARP) requests, Dynamic Host Configuration Protocol (DHCP) discovery and other broadcasts stay inside one subnet, so they reach 50 hosts instead of 500. |
| Security zones | Traffic between subnets must pass a router or firewall, where you can filter it. Guests, staff and servers each get their own zone, usually one subnet per VLAN. |
| Cloud tiers | In a cloud VPC, you put public load balancers, application servers and databases in separate subnets per availability zone, each with its own route table and access rules. |
| Simpler routing | A well-planned set of subnets can be advertised as one aggregate route, which keeps routing tables small. |
A typical cloud VPC split into tiers across two availability zones looks like this:
<figure class="diagram" style="--dg-w: 900px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 900 470" width="900" height="470" role="img" aria-labelledby="subnetting-vpc-tiers-title subnetting-vpc-tiers-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="subnetting-vpc-tiers-title">A cloud VPC split into tiers across two availability zones</title>
<desc id="subnetting-vpc-tiers-desc">VPC 10.20.0.0/16 with three tiers in two availability zones. Public tier: 10.20.0.0/24 in zone A and 10.20.1.0/24 in zone B. Application tier: 10.20.10.0/24 and 10.20.11.0/24. Data tier: 10.20.20.0/24 and 10.20.21.0/24. Only HTTPS is allowed from the public tier to the application tier, and only the database port from the application tier to the data tier.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="899" height="469" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l1"><rect class="dg-tint" x="20" y="20" width="860" height="430" rx="16" fill="#f0f6f9" stroke="#9ac3d9" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 33) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g>
<text x="62" y="47" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700">VPC 10.20.0.0/16</text></g>
<g class="dg-l1"><rect class="dg-tint" x="341.5" y="62" width="67" height="26" rx="13" fill="#e6f0f6" stroke="#8ebcd5" stroke-width="1.2"/><text x="375" y="79.5" font-size="12" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Zone A</text></g>
<g class="dg-l1"><rect class="dg-tint" x="681.5" y="62" width="67" height="26" rx="13" fill="#e6f0f6" stroke="#8ebcd5" stroke-width="1.2"/><text x="715" y="79.5" font-size="12" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Zone B</text></g>
<g class="dg-l7"><g class="dg-icon" transform="translate(44 118) scale(1.1667)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g>
<g class="dg-l7"><text x="84" y="132" font-size="14" class="dg-ink" fill="#6d28d9" font-weight="700">Public tier</text></g>
<text x="84" y="152" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">Load balancers</text>
<g class="dg-l7"><rect class="dg-tint" x="250" y="104" width="250" height="62" rx="10" fill="#f3eefc" stroke="#bd9eee" stroke-width="1.2"/><text x="375" y="141" font-size="15" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.0.0/24</text></g>
<g class="dg-l7"><rect class="dg-tint" x="590" y="104" width="250" height="62" rx="10" fill="#f3eefc" stroke="#bd9eee" stroke-width="1.2"/><text x="715" y="141" font-size="15" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.1.0/24</text></g>
<g class="dg-l4"><g class="dg-icon" transform="translate(44 248) scale(1.1667)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<g class="dg-l4"><text x="84" y="262" font-size="14" class="dg-ink" fill="#c2410c" font-weight="700">Application tier</text></g>
<text x="84" y="282" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">App servers</text>
<g class="dg-l4"><rect class="dg-tint" x="250" y="234" width="250" height="62" rx="10" fill="#faf0ec" stroke="#e4aa92" stroke-width="1.2"/><text x="375" y="271" font-size="15" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.10.0/24</text></g>
<g class="dg-l4"><rect class="dg-tint" x="590" y="234" width="250" height="62" rx="10" fill="#faf0ec" stroke="#e4aa92" stroke-width="1.2"/><text x="715" y="271" font-size="15" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.11.0/24</text></g>
<g class="dg-l2"><g class="dg-icon" transform="translate(44 378) scale(1.1667)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/></g></g>
<g class="dg-l2"><text x="84" y="392" font-size="14" class="dg-ink" fill="#15803d" font-weight="700">Data tier</text></g>
<text x="84" y="412" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">Databases</text>
<g class="dg-l2"><rect class="dg-tint" x="250" y="364" width="250" height="62" rx="10" fill="#ecf5ef" stroke="#96c6a8" stroke-width="1.2"/><text x="375" y="401" font-size="15" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.20.0/24</text></g>
<g class="dg-l2"><rect class="dg-tint" x="590" y="364" width="250" height="62" rx="10" fill="#ecf5ef" stroke="#96c6a8" stroke-width="1.2"/><text x="715" y="401" font-size="15" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10.20.21.0/24</text></g>
<path class="dg-line" d="M375 170V228" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M369 221l6 8 6-8" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M715 170V228" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M709 221l6 8 6-8" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-ok"><rect class="dg-bg-plain" x="502.4" y="188" width="85.2" height="24" rx="12" fill="#ffffff"/><text x="545" y="204.5" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">HTTPS only</text></g>
<path class="dg-line" d="M375 300V358" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M369 351l6 8 6-8" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M715 300V358" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M709 351l6 8 6-8" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-ok"><rect class="dg-bg-plain" x="475.52" y="318" width="138.96" height="24" rx="12" fill="#ffffff"/><text x="545" y="334.5" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">Database port only</text></g>
</svg></figure>
*Figure 1. One VPC block split into three tiers. Arrows show which traffic the rules between subnets allow.*
> [!CHECK]
> A guest laptop on the guest Wi-Fi subnet sends an ARP broadcast. Which devices receive it?
>
> - [ ] Every device in the company, because ARP is needed everywhere
> - [x] Only the devices in the guest Wi-Fi subnet
> - [ ] Only the default gateway
>
> A broadcast stays inside its broadcast domain, which is the subnet (and its VLAN). Routers don't forward it, which is one of the main reasons to subnet.
### Powers of two and the block-size method
Every subnet size is a power of two, because each host bit doubles the number of addresses. You will use this table constantly, so it is worth learning:
| Prefix | Mask | Addresses (block size) | Usable hosts |
|---|---|---|---|
| /20 | 255.255.240.0 | 4096 | 4094 |
| /21 | 255.255.248.0 | 2048 | 2046 |
| /22 | 255.255.252.0 | 1024 | 1022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (point-to-point only, see below) |
| /32 | 255.255.255.255 | 1 | 1 (a single host) |
You don't need to convert to binary every time. The **block-size method** (sometimes called the "magic number") gets you there with simple arithmetic:
1. Find the **interesting octet**: the octet where the mask is neither 255 nor 0.
2. Block size = 256 − the mask value in that octet. For `/27` (mask `.224`), the block size is 256 − 224 = **32**.
3. Subnets start at every multiple of the block size in that octet: `.0`, `.32`, `.64`, `.96`…
4. To find the subnet of any address, round its interesting octet *down* to a multiple of the block size. The broadcast address is the next subnet's start minus one.
For example, which subnet is `192.168.10.77/27` in? 77 rounded down to a multiple of 32 is 64. The subnet is `192.168.10.64/27`, the broadcast is `192.168.10.95` (96 − 1), and the usable hosts are `.65` to `.94`.
It works in any octet. For `10.20.37.200/20`, the mask is `255.255.240.0`, so the interesting octet is the third one and the block size is 256 − 240 = 16. 37 rounded down to a multiple of 16 is 32. The subnet is `10.20.32.0/20` and the broadcast is `10.20.47.255`.
> [!CHECK]
> A subnet uses the mask `255.255.255.240`. What is its block size?
>
> - [ ] 14
> - [x] 16
> - [ ] 240
> - [ ] 32
>
> Block size = 256 − 240 = 16. That gives subnets starting at `.0`, `.16`, `.32`… Fourteen is the number of *usable hosts* in each block, not its size.
### Fixed-length subnetting (FLSM)
With **Fixed-Length Subnet Masking (FLSM)**, you split a block into subnets that all use the same prefix. It's simple and predictable, and it fits well when all segments are about the same size, such as one subnet per site or per cloud tier.
You start from one of two requirements.
**Requirement: a number of subnets.** Borrow `n` bits from the host part so that 2<sup>n</sup> ≥ subnets needed. The new prefix is the old prefix + `n`.
- You need 6 subnets from `192.168.10.0/24`. 2<sup>3</sup> = 8 ≥ 6, so borrow 3 bits. The new prefix is /27: eight subnets of 32 addresses (30 hosts each), starting at `.0`, `.32`, `.64`, `.96`, `.128`, `.160`, `.192` and `.224`.
- You need 12 site networks from `10.20.0.0/16`. 2<sup>4</sup> = 16 ≥ 12, so borrow 4 bits and use /20. The block size is 16 in the third octet: `10.20.0.0/20`, `10.20.16.0/20`, `10.20.32.0/20` … `10.20.240.0/20`. That's 16 subnets of 4094 hosts each, four of them spare for growth.
**Requirement: a number of hosts per subnet.** Keep `h` host bits so that 2<sup>h</sup> − 2 ≥ hosts needed. The new prefix is 32 − `h`.
- Each subnet needs 50 hosts. 2<sup>6</sup> − 2 = 62 ≥ 50 (while 2<sup>5</sup> − 2 = 30 is too small), so keep 6 host bits: /26. `192.168.10.0/24` gives four /26 subnets: `.0`, `.64`, `.128` and `.192`.
> [!NOTE]
> Old textbooks subtract 2 from the *number of subnets* as well, because RFC 950 originally discouraged the all-zeros and all-ones subnets ("subnet zero"). RFC 1878 already called that practice obsolete, and classless routing (RFC 4632) uses every subnet. Modern equipment does too, so this lesson counts all 2<sup>n</sup> subnets.
FLSM's weakness is waste. If one segment needs 100 hosts and another needs 10, both get the same size.
> [!CHECK]
> You must split `192.168.10.0/24` into as many subnets as possible, each with at least 20 usable hosts. Which prefix do you use?
>
> - [ ] /26
> - [x] /27
> - [ ] /28
>
> A /27 gives 30 usable hosts (enough) and eight subnets. A /28 gives only 14 hosts, which is too small. A /26 works but gives only four subnets.
### Variable-length subnetting (VLSM)
**Variable-Length Subnet Masking (VLSM)** lets each subnet have its own prefix, sized to what it needs. A segment with 100 hosts gets a /25, and a segment with 10 hosts gets a /28. It's like cutting a sheet of plywood: cut the big pieces first, and the small ones fit in what's left.
Three rules keep a VLSM plan clean:
1. **Size each segment** with the smallest prefix whose usable hosts cover the need (plus the growth you expect).
2. **Sort from largest to smallest and allocate in that order**, starting at the beginning of the block.
3. **Align every subnet on its own boundary.** A subnet must start at a multiple of its block size. A /27 can start at `.192` (6 × 32) but not at `.208`.
Why largest first? Big blocks have the strictest alignment. If you place a /28 at `.0` and then want a /27, the /27 can't start at `.16`, because 16 isn't a multiple of 32. It has to jump to `.32`, and `.16`–`.31` becomes a hole. Allocating the largest first means each new subnet starts exactly where the previous one ended, with no holes.
<figure class="diagram" style="--dg-w: 880px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 880 414" width="880" height="414" role="img" aria-labelledby="subnetting-flsm-vlsm-title subnetting-flsm-vlsm-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="subnetting-flsm-vlsm-title">192.168.10.0/24 split with FLSM and with VLSM</title>
<desc id="subnetting-flsm-vlsm-desc">Three rulers. The first shows 192.168.10.0/24 split with FLSM into eight equal /27 subnets starting at .0, .32, .64, .96, .128, .160, .192 and .224. The second shows the same block split with VLSM: Sales 192.168.10.0/25 for 100 hosts, Engineering .128/26 for 50 hosts, Guest .192/27 for 25 hosts, and the last /27 for the small subnets. The third zooms on 192.168.10.224/27: Management .224/28 for 10 hosts, two WAN point-to-point links .240/31 and .242/31, and free .244/30 and .248/29.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="879" height="413" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<text x="40" y="40" font-size="14.5" class="dg-text" fill="#17171c" font-weight="700">FLSM: eight equal /27 subnets (30 hosts each)</text>
<g class="dg-l1"><rect class="dg-tint" x="41.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="90.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 1</text>
<text x="90.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.0/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="141.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="190.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 2</text>
<text x="190.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.32/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="241.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="290.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 3</text>
<text x="290.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.64/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="341.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="390.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 4</text>
<text x="390.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.96/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="441.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="490.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 5</text>
<text x="490.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.128/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="541.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="590.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 6</text>
<text x="590.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.160/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="641.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="690.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 7</text>
<text x="690.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.192/27</text>
</g>
<g class="dg-l1"><rect class="dg-tint" x="741.0" y="54" width="98.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="790.0" y="76" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Subnet 8</text>
<text x="790.0" y="94" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224/27</text>
</g>
<path class="dg-line" d="M40.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="40.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.0</text>
<path class="dg-line" d="M140.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="140.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.32</text>
<path class="dg-line" d="M240.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="240.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.64</text>
<path class="dg-line" d="M340.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="340.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.96</text>
<path class="dg-line" d="M440.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="440.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.128</text>
<path class="dg-line" d="M540.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="540.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.160</text>
<path class="dg-line" d="M640.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="640.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.192</text>
<path class="dg-line" d="M740.0 108v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="740.0" y="128" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224</text>
<text x="40" y="172" font-size="14.5" class="dg-text" fill="#17171c" font-weight="700">VLSM: each subnet sized to its need, largest first</text>
<g class="dg-l1"><rect class="dg-tint" x="41.0" y="186" width="398.0" height="52" rx="6" fill="#e6f0f6" stroke="#81b4d0" stroke-width="1.3"/>
<text x="240.0" y="208" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Sales · 100 hosts</text>
<text x="240.0" y="226" font-size="12" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.0/25</text>
</g>
<g class="dg-l2"><rect class="dg-tint" x="441.0" y="186" width="198.0" height="52" rx="6" fill="#e8f2ec" stroke="#8ac09e" stroke-width="1.3"/>
<text x="540.0" y="208" font-size="12.5" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle">Engineering · 50</text>
<text x="540.0" y="226" font-size="12" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.128/26</text>
</g>
<g class="dg-l4"><rect class="dg-tint" x="641.0" y="186" width="98.0" height="52" rx="6" fill="#f9ece7" stroke="#e0a086" stroke-width="1.3"/>
<text x="690.0" y="208" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle">Guest · 25</text>
<text x="690.0" y="226" font-size="12" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.192/27</text>
</g>
<path class="dg-line" d="M40.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="40.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.0</text>
<path class="dg-line" d="M140.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="140.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.32</text>
<path class="dg-line" d="M240.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="240.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.64</text>
<path class="dg-line" d="M340.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="340.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.96</text>
<path class="dg-line" d="M440.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="440.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.128</text>
<path class="dg-line" d="M540.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="540.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.160</text>
<path class="dg-line" d="M640.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="640.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.192</text>
<path class="dg-line" d="M740.0 240v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="740.0" y="260" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224</text>
<rect class="dg-panel" x="741.0" y="186" width="98.0" height="52" rx="6" fill="#f0f0ec" stroke="#cfcfc8"/>
<text x="790.0" y="208" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle">small subnets</text>
<text x="790.0" y="226" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224/27</text>
<text x="40" y="310" font-size="14.5" class="dg-text" fill="#17171c" font-weight="700">Zoom on the grey block, 192.168.10.224/27</text>
<g class="dg-l7"><rect class="dg-tint" x="41.0" y="324" width="398.0" height="52" rx="6" fill="#f0eafb" stroke="#b694ec" stroke-width="1.3"/>
<text x="240.0" y="346" font-size="12.5" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Management · 10</text>
<text x="240.0" y="364" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224/28</text>
</g>
<g class="dg-l3"><rect class="dg-tint" x="441.0" y="324" width="48.0" height="52" rx="6" fill="#f8eee6" stroke="#daa984" stroke-width="1.3"/>
<text x="465.0" y="346" font-size="12.5" class="dg-ink" fill="#b45309" font-weight="700" text-anchor="middle">WAN 1</text>
<text x="465.0" y="364" font-size="12" class="dg-ink" fill="#b45309" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">/31</text>
</g>
<g class="dg-l3"><rect class="dg-tint" x="491.0" y="324" width="48.0" height="52" rx="6" fill="#f8eee6" stroke="#daa984" stroke-width="1.3"/>
<text x="515.0" y="346" font-size="12.5" class="dg-ink" fill="#b45309" font-weight="700" text-anchor="middle">WAN 2</text>
<text x="515.0" y="364" font-size="12" class="dg-ink" fill="#b45309" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">/31</text>
</g>
<rect class="dg-card" x="541.0" y="324" width="98.0" height="52" rx="6" fill="#ffffff" stroke="#cfcfc8" stroke-dasharray="4 3"/>
<text x="590.0" y="346" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">free</text>
<text x="590.0" y="364" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">/30</text>
<rect class="dg-card" x="641.0" y="324" width="198.0" height="52" rx="6" fill="#ffffff" stroke="#cfcfc8" stroke-dasharray="4 3"/>
<text x="740.0" y="346" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">free</text>
<text x="740.0" y="364" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">/29</text>
<path class="dg-line" d="M40.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="40.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.224</text>
<path class="dg-line" d="M140.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="140.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.228</text>
<path class="dg-line" d="M240.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="240.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.232</text>
<path class="dg-line" d="M340.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="340.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.236</text>
<path class="dg-line" d="M440.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="440.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.240</text>
<path class="dg-line" d="M540.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="540.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.244</text>
<path class="dg-line" d="M640.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="640.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.248</text>
<path class="dg-line" d="M740.0 378v6" stroke="#cfcfc8" stroke-width="1.5"/>
<text x="740.0" y="398" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.252</text>
</svg></figure>
*Figure 2. The same /24 with FLSM (top) and VLSM (middle and zoom). With VLSM, the 100-host segment fits, and the small subnets pack into the last /27. The [worked example](#worked-example) builds this plan step by step.*
#### Point-to-point links: /31 and /32
A link between two routers only ever has two devices. A /30 gives it 4 addresses, of which 2 are usable: half the block is lost to the network and broadcast addresses. **RFC 3021** allows a **/31** on point-to-point links. Both addresses are host addresses, and there is no network or broadcast address, because a link with two ends doesn't need them.
A **/32** is a single address. You use it for router loopback interfaces, for host routes, and in firewall rules or cloud security rules that match exactly one machine.
> [!NOTE]
> Most current router and operating system software supports /31 links, but check your platform's documentation before using one, especially on older devices. A /30 always works, at the cost of two extra addresses per link.
> [!CHECK]
> In a VLSM plan, why do you allocate the largest subnets first?
>
> - [ ] Because routers process large subnets before small ones
> - [x] Because large subnets need the strictest alignment, so placing them first avoids holes
> - [ ] Because the first subnet in a block always gets the most usable hosts
>
> A subnet must start at a multiple of its block size. If the large blocks go first, each smaller block starts exactly where the previous one ended. If you go small to large, you skip addresses to reach the next valid boundary.
### Summarization (supernetting)
Subnetting makes a block's prefix longer to split it. **Summarization** (also called **route aggregation** or **supernetting**) does the reverse: it makes the prefix shorter to describe several networks with one route. Instead of telling the rest of the network about four branch subnets, the branch router advertises one **summary route** that covers them all.
Classless Inter-Domain Routing (CIDR, RFC 4632) is what makes this possible. Networks can be summarized into one route only when:
1. they are **contiguous** (no gaps between them),
2. their total size is a **power of two** (2, 4, 8… networks of the same size), and
3. the first network is **aligned**: its start is a multiple of the summary's block size.
Example: `10.20.8.0/24`, `10.20.9.0/24`, `10.20.10.0/24` and `10.20.11.0/24`. Write the third octet in binary:
```text
8 = 000010 00
9 = 000010 01
10 = 000010 10
11 = 000010 11
^^^^^^ 6 common bits
```
The first 16 bits (`10.20`) and 6 more bits are common, so the summary is **`10.20.8.0/22`**. Four /24s are contiguous, four is a power of two, and 8 is a multiple of 4.
Now try `10.20.6.0/24` to `10.20.9.0/24`. They are contiguous, and there are four of them, but 6 is not a multiple of 4. The best you can do is two routes, `10.20.6.0/23` and `10.20.8.0/23`. A single route that covers all four would have to be `10.20.0.0/20`, which also claims 12 /24s you don't have there. Routers would then send traffic to this site for addresses that live somewhere else, or nowhere.
> [!TIP]
> Routers always use the **longest prefix match**: when several routes cover a destination, the most specific one wins. So a summary can coexist with a more specific route for a subnet that lives elsewhere. Use this on purpose, not as a fix for a plan that wasn't aligned.
> [!CHECK]
> Can `10.20.20.0/24` and `10.20.21.0/24` (the data-tier subnets in Figure 1) be summarized into one route?
>
> - [x] Yes, as `10.20.20.0/23`
> - [ ] Yes, as `10.20.20.0/22`
> - [ ] No, two networks can never be summarized
>
> They are contiguous, two is a power of two, and 20 is even, so they share the first 23 bits. A /22 would also cover `10.20.22.0/24` and `10.20.23.0/24`, which aren't part of the data tier.
### Troubleshooting addressing faults
Three faults cause most addressing tickets. Each has a recognisable symptom. The examples use the branch plan from the [worked example](#worked-example): Sales `192.168.10.0/25` (gateway `.1`) and Engineering `192.168.10.128/26` (gateway `.129`).
| Fault | Example | What the host concludes | Symptom |
|---|---|---|---|
| Mask too short | Sales PC `192.168.10.20` configured with `/24` instead of `/25` | Engineering's `192.168.10.130` is "local", so it sends ARP requests instead of using the gateway. | Internet and Sales work. Engineering is unreachable: ARP for `.130` gets no answer, because Engineering is a different VLAN. (A router with proxy ARP enabled may answer for it and hide the fault.) |
| Mask too long | Sales PC `192.168.10.20` configured with `/28` | Its subnet is `192.168.10.16/28` (`.17`–`.30`), so most of Sales and the gateway `.1` are "remote". | It can only reach Sales hosts `.17`–`.30` directly. The gateway is outside its subnet, so nothing off-subnet works either (see next row). |
| Gateway outside the subnet | Engineering PC `192.168.10.140/26` with gateway `192.168.10.1` | `.1` is not in `192.168.10.128/26`, so the host can't reach the gateway directly. | Local hosts work, everything else fails. Linux refuses the route (`Error: Nexthop has invalid gateway.`). Other systems may accept the setting and fail silently. |
| Overlapping subnets | A new lab network `192.168.10.192/26` is added on another router | Two places now claim `.192`–`.255`. | Each router follows its longest matching route. The head office only has the branch's `/24` summary, so the lab's `/26` wins there: traffic for Guest Wi-Fi and Management goes to the lab instead. Reachability now depends on where you test from, which makes the cause hard to spot. |
A quick test for any host: compute its network from its address and mask, then check that the gateway is inside that network and that the mask matches the documented plan.
> [!CHECK]
> A host is configured as `192.168.10.70/27` with default gateway `192.168.10.1`. It can ping its neighbours but nothing outside. What is wrong?
>
> - [ ] The mask is too short, so the host thinks remote hosts are local
> - [x] The gateway is outside the host's subnet, `192.168.10.64/27`
> - [ ] The host's address is the broadcast address of its subnet
>
> 70 rounded down to a multiple of 32 is 64, so the subnet is `.64`–`.95`. The gateway `.1` is not in it, so the host can't deliver off-subnet traffic. `.95` is the broadcast address, not `.70`.
## How it works
Designing an addressing plan from requirements follows the same steps every time:
1. **Collect the requirements.** List every segment (VLAN, cloud tier, link) with its host count today and the growth you expect.
2. **Size each segment.** Find the smallest prefix whose usable hosts cover the need plus growth. Point-to-point links get a /31 (or a /30 where /31 isn't supported).
3. **Size the parent block.** Add up the block sizes and round up to the next power of two. That gives you the smallest block that fits, and lets the site be summarized as one route.
4. **Sort and allocate.** Sort segments from largest to smallest. Place each one at the next free address that is a multiple of its block size.
5. **Assign gateways.** By convention, the first usable address of each subnet is the gateway. Whatever you choose, use the same convention everywhere.
6. **Check the plan.** Every subnet sits inside the parent block. No two subnets overlap. Every subnet has enough hosts. The leftover space is in large, aligned pieces you can use later.
7. **Document and reserve.** Record the plan, the summary route and the free blocks, so the next person doesn't create an overlap.
<figure class="diagram" style="--dg-w: 1060px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1060 172" width="1060" height="172" role="img" aria-labelledby="subnetting-workflow-title subnetting-workflow-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="subnetting-workflow-title">The VLSM design workflow</title>
<desc id="subnetting-workflow-desc">Six steps: gather requirements (hosts per segment plus growth), size each segment with the smallest prefix that fits, sort from largest to smallest, allocate aligned blocks with no gaps, check containment, overlaps and capacity, and document the plan, summary route and free space.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1059" height="171" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="24" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="46" cy="48" r="12" fill="#0369a1"/><text x="46" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(129.333 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></g></g>
<text x="38" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Requirements</text>
<text x="38" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Hosts per segment</text>
<text x="38" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">plus growth</text>
<path class="dg-line" d="M175.333 86H191.333" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M183.333 80l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="197.333" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="219.333" cy="48" r="12" fill="#0369a1"/><text x="219.333" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(302.667 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z"/><path d="m14.5 12.5 2-2"/><path d="m11.5 9.5 2-2"/><path d="m8.5 6.5 2-2"/><path d="m17.5 15.5 2-2"/></g></g>
<text x="211.333" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Size</text>
<text x="211.333" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Smallest prefix</text>
<text x="211.333" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">that fits</text>
<path class="dg-line" d="M348.667 86H364.667" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M356.667 80l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="370.667" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="392.667" cy="48" r="12" fill="#0369a1"/><text x="392.667" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(476 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m3 16 4 4 4-4"/><path d="M7 20V4"/><path d="M11 4h10"/><path d="M11 8h7"/><path d="M11 12h4"/></g></g>
<text x="384.667" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Sort</text>
<text x="384.667" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Largest segment</text>
<text x="384.667" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">first</text>
<path class="dg-line" d="M522 86H538" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M530 80l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="544" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="566" cy="48" r="12" fill="#0369a1"/><text x="566" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(649.333 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g></g>
<text x="558" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Allocate</text>
<text x="558" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Aligned blocks,</text>
<text x="558" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">no gaps</text>
<path class="dg-line" d="M695.333 86H711.333" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M703.333 80l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="717.333" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="739.333" cy="48" r="12" fill="#0369a1"/><text x="739.333" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">5</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(822.667 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g>
<text x="731.333" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Check</text>
<text x="731.333" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Containment,</text>
<text x="731.333" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">overlaps, capacity</text>
<path class="dg-line" d="M868.667 86H884.667" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M876.667 80l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="890.667" y="24" width="145.333" height="124" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="912.667" cy="48" r="12" fill="#0369a1"/><text x="912.667" y="52.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">6</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(996 36) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></g></g>
<text x="904.667" y="86" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Document</text>
<text x="904.667" y="106" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Plan, summary</text>
<text x="904.667" y="123" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">route, free space</text>
</svg></figure>
*Figure 3. The VLSM design workflow.*
> [!NOTE]
> Cloud providers usually reserve some addresses in every subnet for their own services. For example, AWS documents five reserved addresses per VPC subnet (the first four and the last; checked November 2026), so a /24 there gives 251 usable addresses, not 254. Other providers reserve a different number. This is provider-specific and can change: check your provider's current documentation when you size cloud subnets.
> [!CHECK]
> A site needs a /25, a /26 and a /27. What is the smallest single block that holds all three and can be advertised as one route?
>
> - [ ] A /25, because the largest subnet is a /25
> - [x] A /24, because 128 + 64 + 32 = 224 addresses, rounded up to 256
> - [ ] A /23, because VLSM always needs twice the space
>
> The three blocks need 224 addresses. The next power of two is 256, a /24. Placed largest first (`.0/25`, `.128/26`, `.192/27`), they fit with a /27 to spare.
## Worked example
A branch office has `192.168.10.0/24`. It needs:
| Segment | Hosts needed |
|---|---|
| Sales | 100 |
| Engineering | 50 |
| Guest Wi-Fi | 25 |
| Management (switches, access points) | 10 |
| WAN link 1 (to head office) | 2 |
| WAN link 2 (backup link) | 2 |
**Step 1 — size each segment.**
| Segment | Hosts | Smallest prefix | Why |
|---|---|---|---|
| Sales | 100 | /25 | 2<sup>7</sup> − 2 = 126 ≥ 100; a /26 (62) is too small |
| Engineering | 50 | /26 | 62 ≥ 50 |
| Guest Wi-Fi | 25 | /27 | 30 ≥ 25 |
| Management | 10 | /28 | 14 ≥ 10 |
| WAN links | 2 | /31 | RFC 3021 point-to-point |
**Step 2 — check that it fits.** 128 + 64 + 32 + 16 + 2 + 2 = 244 addresses, which is no more than 256. It fits in the /24.
**Step 3 — allocate largest first.** Each subnet starts where the previous one ended, and each start is a multiple of its own block size:
| Segment | Subnet | Mask | Usable range | Broadcast | Gateway | Spare hosts |
|---|---|---|---|---|---|---|
| Sales | `192.168.10.0/25` | 255.255.255.128 | `.1` – `.126` | `.127` | `.1` | 26 |
| Engineering | `192.168.10.128/26` | 255.255.255.192 | `.129` – `.190` | `.191` | `.129` | 12 |
| Guest Wi-Fi | `192.168.10.192/27` | 255.255.255.224 | `.193` – `.222` | `.223` | `.193` | 5 |
| Management | `192.168.10.224/28` | 255.255.255.240 | `.225` – `.238` | `.239` | `.225` | 4 |
| WAN link 1 | `192.168.10.240/31` | 255.255.255.254 | `.240` – `.241` | none | — | 0 |
| WAN link 2 | `192.168.10.242/31` | 255.255.255.254 | `.242` – `.243` | none | — | 0 |
| *Free* | `192.168.10.244/30`, `192.168.10.248/29` | | 12 addresses | | | |
**Step 4 — summarize.** Every subnet sits inside `192.168.10.0/24`, so the head office needs only one route to the branch: `192.168.10.0/24`. If the branch gets a fifth VLAN later, it comes out of the free space and the summary doesn't change.
**Step 5 — compare with FLSM.** With FLSM, the 100-host Sales segment forces every subnet to be a /25. A /24 holds only two /25s, so the six segments don't fit at all. VLSM fits all six and still leaves 12 addresses free.
You can check this plan with Python's standard `ipaddress` module, which the lab uses:
```python
import ipaddress
plan = ["192.168.10.0/25", "192.168.10.128/26", "192.168.10.192/27",
"192.168.10.224/28", "192.168.10.240/31", "192.168.10.242/31"]
nets = [ipaddress.ip_network(p) for p in plan]
print(list(ipaddress.collapse_addresses(nets)))
print(ipaddress.ip_network("192.168.10.192/26").overlaps(nets[2]))
```
Expected output:
```text
[IPv4Network('192.168.10.0/25'), IPv4Network('192.168.10.128/26'), IPv4Network('192.168.10.192/27'), IPv4Network('192.168.10.224/28'), IPv4Network('192.168.10.240/30')]
True
```
`collapse_addresses` merges only what can be merged exactly: the two /31 links become `192.168.10.240/30`. The other subnets have different sizes and stay separate, which is why the summary route `192.168.10.0/24` is a design choice (it includes the free space) rather than an exact merge. The second line confirms that the "lab network" from the troubleshooting table overlaps Guest Wi-Fi.
## Common pitfalls
- **Forgetting the network and broadcast addresses.** A /27 has 32 addresses but only 30 usable hosts. Size subnets by usable hosts, not by block size.
- **Starting a subnet on the wrong boundary.** `192.168.10.208/27` is not a valid subnet: 208 is not a multiple of 32. Tools usually reject it, or quietly correct it to `192.168.10.192/27`, and then it overlaps another subnet.
- **Allocating small subnets first.** It leaves holes that larger subnets can't use. Sort largest first.
- **Sizing with no room to grow.** A subnet that's 100 % full today needs renumbering tomorrow. Renumbering is far more work than leaving spare space at the start.
- **Ignoring cloud reservations.** A cloud subnet has fewer usable addresses than the same prefix on-premises. Check the provider's documentation.
- **Summaries that aren't aligned.** Advertising `10.20.0.0/20` to cover four networks starting at `10.20.6.0` attracts traffic for addresses the site doesn't own.
- **Reusing "popular" private ranges.** `192.168.0.0/24`, `192.168.1.0/24` and `10.0.0.0/16` are defaults on home routers and in cloud templates. If you use them, VPN users and new partners are likely to overlap with you.
## Security considerations
Subnets are the foundation of **network segmentation**: dividing a network into zones so that a compromise in one zone doesn't give access to everything.
- **One purpose per subnet.** Put guests, staff, servers, management interfaces and voice in separate subnets (and VLANs). Then the router or firewall between them is a place where you can apply policy.
- **Least privilege between subnets.** Allow only the traffic each zone needs. For example, allow the application tier to reach the database port of the data tier, and deny everything else. Deny by default.
- **Protect the management subnet.** Switch and router management interfaces belong in their own small subnet, reachable only from administrator workstations or a jump host.
- **Write rules with the plan in mind.** Aligned blocks give clean rules: `10.20.10.0/23` matches exactly the application tier in Figure 1. Messy plans lead to broad rules ("allow `10.20.0.0/16`") that defeat segmentation.
- **Avoid overlaps with partners and remote users.** Site-to-site VPNs, cloud VPC peering and many cloud interconnects can't route between overlapping ranges. Overlaps force workarounds such as NAT between the sites, which hide the real source address and complicate logs and firewall rules. Pick less common RFC 1918 ranges and keep a central record of what's allocated.
- **Keep the plan documented.** An undocumented subnet is often one nobody monitors. An IP address management (IPAM) tool or even a version-controlled file of allocations helps.
> [!IMPORTANT]
> Segmentation reduces the impact of a compromise; it doesn't replace host security. A subnet boundary only helps if a router or firewall between subnets actually filters traffic.
## Summary
- Subnetting splits a block into smaller networks by lengthening the prefix. It shrinks broadcast domains, creates security zones and keeps routing tidy.
- Block size = 256 − the mask value in the interesting octet. Subnets start at multiples of the block size.
- FLSM: borrow `n` bits for 2<sup>n</sup> subnets, or keep `h` host bits for 2<sup>h</sup> − 2 hosts. It's simple but wastes space when segments differ in size.
- VLSM: size each segment, sort largest first, allocate on aligned boundaries. Use /31 for point-to-point links (RFC 3021) and /32 for single hosts.
- Summarization works when networks are contiguous, a power of two in number and aligned. Routers pick the longest prefix match.
- Most addressing faults are a wrong mask, an overlap, or a gateway outside the subnet. Compute the host's network and check the gateway is inside it.
## Glossary
| Term | Definition |
|---|---|
| Subnetting | Dividing an address block into smaller networks by using a longer prefix. |
| Subnet | A network carved out of a larger block; one broadcast domain, usually one VLAN. |
| Prefix length | The number of leading bits of an address that identify the network (for example `/26`). |
| Block size | The number of addresses in a subnet (2<sup>host bits</sup>); subnets start at multiples of it. |
| Interesting octet | The octet in which the subnet mask is neither 255 nor 0; where subnet boundaries fall. |
| Block-size method | Finding subnet boundaries with 256 − mask value, instead of converting to binary. |
| Fixed-Length Subnet Masking (FLSM) | Splitting a block into subnets that all use the same prefix length. |
| Variable-Length Subnet Masking (VLSM) | Splitting a block into subnets of different prefix lengths, each sized to its need. |
| Alignment | A subnet starts at an address that is a multiple of its own block size. |
| /31 link | A two-address subnet for point-to-point links where both addresses are hosts (RFC 3021). |
| /32 | A prefix that matches exactly one address; used for loopbacks, host routes and precise rules. |
| Summarization (route aggregation, supernetting) | Advertising several contiguous, aligned networks as one shorter-prefix route. |
| Summary route | The single route that covers a group of networks after summarization. |
| Classless Inter-Domain Routing (CIDR) | Addressing and routing with arbitrary prefix lengths instead of fixed classes (RFC 4632). |
| Longest prefix match | The routing rule that picks the most specific route that matches the destination. |
| Network segmentation | Dividing a network into zones with controlled traffic between them. |
| IP address management (IPAM) | Tools and processes for recording and allocating address space. |
## Check your understanding
1. Why does every subnet size have to be a power of two? What would go wrong with a "subnet of 100 addresses"?
2. You need 10 subnets of at least 1,000 hosts each from `10.20.0.0/16`. Which prefix do you use, and how many such subnets fit?
3. A colleague allocated a /28 at `.0`, then a /26, then a /25 in a /24. Where did they place each one, and how much space did they lose?
4. Why can `10.20.4.0/24` to `10.20.7.0/24` be summarized into one route, but `10.20.5.0/24` to `10.20.8.0/24` can't?
5. A host can reach the Internet but not a server in a neighbouring subnet of the same building. Which addressing fault would you check first, and how?
6. Your company and a newly acquired company both use `10.0.0.0/16`. What breaks when you connect them with a VPN, and what are your options?
## References
- [RFC 950](https://www.rfc-editor.org/rfc/rfc950) — Internet Standard Subnetting Procedure.
- [RFC 1878](https://www.rfc-editor.org/rfc/rfc1878) — Variable Length Subnet Table For IPv4 (Informational; notes that excluding subnet zero is obsolete).
- [RFC 4632](https://www.rfc-editor.org/rfc/rfc4632) — Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan.
- [RFC 3021](https://www.rfc-editor.org/rfc/rfc3021) — Using 31-Bit Prefixes on IPv4 Point-to-Point Links.
- [RFC 1918](https://www.rfc-editor.org/rfc/rfc1918) — Address Allocation for Private Internets.
- [RFC 5737](https://www.rfc-editor.org/rfc/rfc5737) — IPv4 Address Blocks Reserved for Documentation.
- [Python `ipaddress` module](https://docs.python.org/3/library/ipaddress.html) — standard-library documentation.
- [AWS: Subnet CIDR blocks](https://docs.aws.amazon.com/vpc/latest/userguide/subnet-sizing.html) — example of provider-reserved addresses.