IPv4 addressing · Fundamentals · Module 3
Choosing a prefix for a requirement
Show topologyHide topology
Interfaces and addresses · Et = Ethernet. LAN C, LAN D and branch LAN 2 are planned and not cabled yet.
- 192.168.8.0/26 · LAN AR1 Et0/0 192.168.8.1H1 eth0 192.168.8.10
- 192.168.8.64/26 · LAN BR1 Et0/1 192.168.8.65R3 Et0/0 192.168.8.126
- 192.168.9.224/30R1 Et0/2 192.168.9.225R2 Et0/0 192.168.9.226
- 192.168.9.228/31R2 Et0/2 192.168.9.228R4 Et0/0 192.168.9.229
- 192.168.9.0/25 · branch LAN 1 · SW1R2 Et0/1 192.168.9.1no other device yet
- 192.168.9.192/27 · branch LAN 3 · SW2R4 Et0/1 192.168.9.193no other device yet
Device icons joined by plain cables, each cable labeled with its subnet. Down the middle, top to bottom: R3, a router; R1, the HQ router; R2, the branch router; R4, a branch router; and the switch SW2. R3 is cabled to R1 (192.168.8.64/26), R1 to R2 (192.168.9.224/30), R2 to R4 (192.168.9.228/31) and R4 to SW2 (192.168.9.192/27). At the upper left, the host H1, a laptop, is cabled down from its base to R1 (192.168.8.0/26). Left of R2, the switch SW1 is cabled across to it (192.168.9.0/25).
What a point-to-point link is
Two kinds of need
Branch LAN 1 must hold 100 hosts, and HQ must get 4 LANs from one /24. Where does a plan start?
HQ started from its block and cut it into 4 LANs. A plan usually starts the other way around, from what each network must hold.
Some needs are sizes, how many devices a network must hold. The branch’s LAN 1 needs 100 hosts, LAN 2 needs 50 and LAN 3 needs 20, so each prefix must leave enough host bits.
Other needs are subnet counts, how many networks a block must make. HQ needs 4 LANs from its one block, so its prefix must borrow enough subnet bits.
The links from R1 to R2 and from R2 to R4 each join just two routers. A link with exactly two ends like these is a point-to-point link. A point-to-point link needs exactly two host addresses.
The link from R1 to R2 has 4 addresses (Figure 3.1), its two ends plus its network and broadcast address, and the link from R2 to R4 has 2 and uses both.
R1, the HQ router, at the top; R2, the branch router, under it; R4, a branch router, under R2, joined top to bottom by two cables. Right of the cable from R1 to R2, the label 192.168.9.224/30; left of it, a column of four cells, top to bottom: “.224 network”, “.225 R1”, “.226 R2” and “.227 broadcast”. Beside the cable from R2 to R4, drawn the same way, the label 192.168.9.228/31 and a highlighted column of two cells: “.228 R2” and “.229 R4”.
Key idea
Pick the prefix from the need: enough hosts in each subnet, or enough subnets in the block.
How it works
From a need to a prefix
Branch LAN 1 needs 100 hosts. Which prefix gives it enough, with the fewest addresses left over?
h host bits give 2ʰ addresses, two of which go to no device, the all-zeros network and the all-ones broadcast, so they hold 2ʰ − 2 hosts.
To fit H hosts, then, find the smallest h with 2ʰ − 2 ≥ H, the host rule. The prefix is 32 − h, since it counts every bit that is not a host bit, the network and subnet bits together.
Count the hosts, not the addresses. A /26 has 64 addresses but holds 62 hosts, so a LAN of more than 62 devices does not fit it.
Why the smallest h? Each extra host bit doubles the addresses the subnet takes from the block, and the added addresses stay unused. So take the fewest host bits that fit, which gives the longest prefix that still fits.
Subnets work the same way from the other side. To make N equal subnets, find the smallest s with 2ˢ ≥ N and add s to the block’s prefix. HQ needs 4 LANs, and 2 bits make 4, so /24 becomes /26.
Step through Figure 3.2 to find the prefix for branch LAN 1 from its host need, and for a link from its two ends.
Step 1 of 7
Branch LAN 1 needs 100 hosts. h host bits make 2ʰ addresses, two of which go to no device.
Step 2 of 7
Try 6 host bits: 2⁶ − 2 = 62 hosts. That is too few for 100, and 5 bits give even fewer, 30.
Step 3 of 7
Try 7 host bits: 2⁷ − 2 = 126 hosts. That holds all 100, so 7 is the fewest host bits that fit.
Step 4 of 7
LAN 1 keeps 7 bits for its hosts. Every other bit of the 32 is a network bit, and the prefix counts those.
LAN 1 keeps 7 host bits. Which prefix is that?
- /25 (Correct): An address has 32 bits. 7 are host bits, so 32 − 7 = 25 are network bits: /25. It holds 126 hosts, enough for 100.
- /7: That writes the host bits after the slash, but the prefix counts the network bits, the ones of the mask.
- /26: /26 borrows one more bit, which halves the addresses to 64 and leaves 62 hosts, too few for 100.
Step 5 of 7
32 − 7 = 25, so the prefix is /25, mask 255.255.255.128. It is the longest prefix whose hosts still fit, since /26 would hold too few.
Step 6 of 7
A link of two routers needs only 2 hosts. A /30 gives 4 addresses, 2 of them hosts. A /31 gives 2, and on a point-to-point link both are host addresses.
Step 7 of 7
Take the fewest host bits whose hosts still fit: LAN 1 gets /25. A two-router link gets a /30, or a /31, where both addresses are hosts.
At the top, “Branch LAN 1 needs 100 hosts”. Under it, three rows, one per number of host bits: “5 host bits: 2⁵ − 2 = 30”, “6 host bits: 2⁶ − 2 = 62” and “7 host bits: 2⁷ − 2 = 126”; from step 2, “too few” at the right end of the first two rows; from step 3, “fits” at the right end of the third. From step 5, under the rows, “/25 · mask 255.255.255.128”. From step 6, “A link needs 2 hosts” and two rows: “/30: 4 addresses, 2 hosts” and “/31: 2 addresses, both hosts”. At step 7, at the foot, “LAN 1: /25 · a link: /30 or /31”.
Predict the next step, then go on.
Set the prefix, then submit it.
/25: 2 subnets of 128 addresses, 126 hosts each
- Network address
- 192.168.9.0
- First host
- 192.168.9.1
- Last host
- 192.168.9.126
- Broadcast address
- 192.168.9.127
Task 1 of 1
Branch LAN 3 needs 20 hosts. Set the longest prefix that still holds them.
| Subnet | Network address | First host | Last host | Broadcast address |
|---|---|---|---|---|
| 1 | .0 | .1 | .126 | .127 |
| 2 | .128 | .129 | .254 | .255 |
Task 1 of 1 Branch LAN 3 needs 20 hosts. Set the longest prefix that still holds them.
Answer
/27
4 host bits hold only 14 hosts, too few. 5 host bits hold 30, enough for 20. So 32 − 5 = 27: /27, as the branch plan gives LAN 3.
Key idea
Hosts decide the host bits: the fewest h with 2ʰ − 2 ≥ H, and the prefix is 32 − h. Subnets decide the subnet bits: the fewest s with 2ˢ ≥ N.
Two ends, two addresses: /30 and /31
A link between two routers needs two host addresses. Which prefix gives exactly two?
The host rule gives /30 for two hosts, since 2 host bits make 4 addresses and 4 − 2 = 2. Links are commonly numbered this way, with four addresses per link, the network address, the two ends and the broadcast address.
Can a /31 do it with 2 addresses? By the host rule its 1 host bit holds none, but a point-to-point link has only two endpoints and needs no broadcast address. On a /31 point-to-point link, both addresses count as host addresses, one for each end.
If you see a /31 on a point-to-point link, it is a valid prefix, not a mistake. It saves two addresses over a /30, as on R2’s link to R4.
Key idea
A two-router link needs two host addresses. A /30 gives them out of 4, a /31 out of 2, because on a point-to-point link both are hosts.
One end is given; find the other end’s address.