Using VLSM, how would you carve the IPv4 block 10.40.4.0/22 into subnets for 300, 120, 50 and 20 hosts plus three point-to-point links?
answer
- size first, then place
- smallest prefix that covers the need
- sort descending before placing
- each start = previous end + 1
- count the spare per subnet
basics
~10 sSize each segment, then place largest first: 10.40.4.0/23 (300), 10.40.6.0/25 (120), 10.40.6.128/26 (50), 10.40.6.192/27 (20), then 10.40.6.224/30, .228/30 and .232/30 for the links, leaving 10.40.6.236 to 10.40.7.255 free.
solid answer
~40 sFirst size each segment: the smallest subnet whose `2^(32-n) - 2` usable hosts covers the need, so 300 gets a `/23` (510), 120 a `/25` (126), 50 a `/26` (62), 20 a `/27` (30), and each link a `/30` (2) - or a `/31` under RFC 3021. Then allocate largest first from the bottom of `10.40.4.0/22`: `10.40.4.0/23`, `10.40.6.0/25`, `10.40.6.128/26`, `10.40.6.192/27`, then `10.40.6.224/30`, `10.40.6.228/30` and `10.40.6.232/30`. Each block starts where the previous one ended and lands on a multiple of its own size, so nothing overlaps. That uses 748 of 1,024 addresses and leaves `10.40.6.236` through `10.40.7.255` - 276 addresses, including a whole `/24` - for growth. The spare inside the LANs is 210, 6, 12 and 10; the `/25` is tight, so if that segment will grow I would give it a `/24` now.
go deeper
Recall the sizing rule: usable hosts are 2^(32-n) minus 2, so pick the smallest subnet that covers each count, then place the biggest block first.
Walk the plan aloud: size each segment, place largest first so each start is the previous end plus one, then state the free range and the spare in each subnet.
Defend the headroom choices: the tight /25, the 210 spare in the /23, /30 versus /31 on the links, and keeping the leftover /24 whole for the segment most likely to grow.
Treat the plan as a growth budget: where renumbering would hurt most, buy headroom now; where segments are stable, size tightly and keep one large aligned block in reserve.
## The brief The block is `10.40.4.0/22`: 1,024 addresses from `10.40.4.0` to `10.40.7.255`, inside the RFC 1918 private block `10.0.0.0/8`. It must hold four LANs of about 300, 120, 50 and 20 hosts - each count already including the router's own interface - and three point-to-point links between routers. The method has two passes: **size** every segment, then **place** the segments largest first. ## Step 1 - size every segment A `/n` prefix holds `2^(32-n)` addresses and `2^(32-n) - 2` usable hosts. For each segment, pick the longest prefix (the smallest subnet) whose usable count still covers the need: | Segment | Hosts needed | Prefix | Addresses | Usable | Spare hosts | |---|---|---|---|---|---| | LAN A | 300 | `/23` | 512 | 510 | 210 | | LAN B | 120 | `/25` | 128 | 126 | 6 | | LAN C | 50 | `/26` | 64 | 62 | 12 | | LAN D | 20 | `/27` | 32 | 30 | 10 | | Links 1-3 | 2 each | `/30` | 4 each | 2 each | 0 | For each LAN the next size down fails: a `/24` gives 254, a `/26` gives 62, a `/27` gives 30 and a `/28` gives 14 - each below its segment's need. For the links the next size down is a `/31`, which works only under RFC 3021, covered below. ## Step 2 - place them largest first Work from the bottom of the block and give each subnet the next free address: 1. **LAN A, `/23`:** starts at `10.40.4.0`, the block's first address, which is a multiple of 512. It ends at `10.40.5.255`. 2. **LAN B, `/25`:** the next free address is `10.40.6.0`, a multiple of 128 in the last octet. It ends at `10.40.6.127`. 3. **LAN C, `/26`:** next free `10.40.6.128`, a multiple of 64. It ends at `10.40.6.191`. 4. **LAN D, `/27`:** next free `10.40.6.192`, a multiple of 32. It ends at `10.40.6.223`. 5. **Links:** `10.40.6.224/30`, `10.40.6.228/30` and `10.40.6.232/30`, each a multiple of 4. The last ends at `10.40.6.235`. Because every block placed earlier is a multiple of the current block's size, the next free address is always a legal start; no padding was needed at any step. ## The finished plan | Segment | Prefix | First host | Last host | Broadcast | |---|---|---|---|---| | LAN A | `10.40.4.0/23` | 10.40.4.1 | 10.40.5.254 | 10.40.5.255 | | LAN B | `10.40.6.0/25` | 10.40.6.1 | 10.40.6.126 | 10.40.6.127 | | LAN C | `10.40.6.128/26` | 10.40.6.129 | 10.40.6.190 | 10.40.6.191 | | LAN D | `10.40.6.192/27` | 10.40.6.193 | 10.40.6.222 | 10.40.6.223 | | Link 1 | `10.40.6.224/30` | 10.40.6.225 | 10.40.6.226 | 10.40.6.227 | | Link 2 | `10.40.6.228/30` | 10.40.6.229 | 10.40.6.230 | 10.40.6.231 | | Link 3 | `10.40.6.232/30` | 10.40.6.233 | 10.40.6.234 | 10.40.6.235 | ## What is left, and what each choice cost - **Allocated:** 512 + 128 + 64 + 32 + 3 x 4 = 748 of 1,024 addresses. - **Free:** `10.40.6.236` through `10.40.7.255`, 276 addresses, which split into the aligned blocks `10.40.6.236/30`, `10.40.6.240/28` and `10.40.7.0/24`. - **Spare inside the LANs:** 210 in LAN A, 6 in LAN B, 12 in LAN C and 10 in LAN D - 238 host addresses allocated but unused. - **Overhead:** two addresses per subnet for network and broadcast - 8 across the four LANs and 6 across the three `/30` links. - **The `/31` option:** numbering the links as `/31` under RFC 3021 makes both addresses of each pair usable, so the links take `10.40.6.224/31`, `10.40.6.226/31` and `10.40.6.228/31` - 6 addresses instead of 12 - and the free space grows to 282 (`10.40.6.230/31`, `10.40.6.232/29`, `10.40.6.240/28` and `10.40.7.0/24`). The spare figures are the real design decision. LAN B fits a `/25` with only six addresses to spare; if that segment is expected to grow, give it a `/24` now - `10.40.7.0/24` is still whole - rather than renumber it later. LAN A's 210 spare is the price of crossing 254 hosts: no prefix exists between `/24` and `/23`. ## Checking the plan before it ships - **Alignment:** each network address is a multiple of its block size - for LAN D, 192 = 6 x 32 in the last octet. - **No overlap:** sorted by start, every block starts after the previous one ends; here each starts exactly one address later. - **Containment:** the last allocated address, `10.40.6.235`, lies inside the `/22`, whose last address is `10.40.7.255`. - **Recount** every number a second time; an off-by-one boundary is the commonest planning defect.
- How does the plan change if the three links use /31 prefixes instead of /30?RFC 3021 lets both addresses of a `/31` be hosts on a point-to-point link, so each link needs 2 addresses instead of 4. The links become `10.40.6.224/31`, `10.40.6.226/31` and `10.40.6.228/31`, using 6 addresses instead of 12, and the free space grows from 276 to 282: `10.40.6.230/31`, `10.40.6.232/29`, `10.40.6.240/28` and `10.40.7.0/24`.
- Can the plan use 10.40.4.0/23, whose subnet bits inside the /22 are all zeros?Yes. RFC 950 (1985) said the all-zeros and all-ones subnet values should not be assigned, to keep their meanings of "this network" and "all subnets". RFC 1812 later deprecated the all-subnets broadcast and told routers to treat every route as a generalized network prefix, so classless plans use the first and last subnets like any other.
- Why give the 300-host LAN one /23 rather than two /24s?One LAN segment needs one prefix covering all its hosts. Split into two `/24`s, hosts in `10.40.4.0/24` would treat `10.40.5.x` as off-link and send that traffic through a router, so you would have built two subnets, each needing its own router interface. If the segment really is one LAN, the `/23` is the honest size.
saying these in an interview costs you the question
- A /24 is enough for 300 hosts if you count carefully.
- Place the smallest subnets first so the big one takes what is left.
- 10.40.5.0/23 is a valid second /23 inside 10.40.4.0/22.
- A /25 gives 128 usable host addresses.
- Each point-to-point link needs at least a /29.