VLSM (Variable Length Subnet Masking)
VLSM lets you use different prefix lengths so that no addresses are wasted. Procedure: sort requirements from largest to smallest and allocate in that order.
Example: from 192.168.5.0/24 provide LAN A (100 hosts), LAN B (50 hosts), LAN C (20 hosts), and a router link (2 hosts).
- LAN A: 100 hosts needs /25 → 192.168.5.0/25 (0-127)
- LAN B: 50 hosts needs /26 → 192.168.5.128/26 (128-191)
- LAN C: 20 hosts needs /27 → 192.168.5.192/27 (192-223)
- Link: 2 hosts needs /30 → 192.168.5.224/30 (224-227)
Why "largest first"?
If you gave the 20-host LAN a /25 first, you would waste half the parent /24, and the 100-host LAN would no longer fit. Sorting by size packs the block tightly and leaves one contiguous free area at the end for growth.
Prefix needed for N hosts
Find the smallest h such that 2^h − 2 ≥ N, then prefix = 32 − h:
| Hosts needed | Host bits | Prefix |
|---|---|---|
| 2 | /30 | |
| 6 | /29 | |
| 14 | /28 | |
| 30 | /27 | |
| 62 | /26 | |
| 126 | /25 | |
| 254 | /24 |
Default gateway in practice
Every host needs:
- Its own IP address inside the usable range.
- The correct subnet mask (same as the rest of the subnet).
- The default gateway = the router's interface address on this subnet (also inside the usable range, often
.1by convention). - At least one DNS server address (may be the router or a public resolver).
If the mask is wrong, two PCs on the "same" switch may think they are on different networks and send traffic to the gateway unnecessarily — or fail to reach each other. If the gateway is wrong or down, local traffic may still work (ping to a neighbour) while Internet access fails. That pattern is a classic troubleshooting clue (see Unit 9).
Remember
- VLSM: sort requirements largest → smallest; pick the smallest prefix that fits each.
- Gateway must be on the same subnet as the host.
- Wrong mask or wrong gateway are among the most common IP faults.
Default gateway
To reach any address outside its own subnet, a host sends traffic to its default gateway (the router interface on its subnet). A wrong gateway or mask is among the most common causes of connectivity faults.