Unit 4 · Addressing Network Devices

4.5.1VLSM and the default gateway

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/25 · 126 hostsLAN B/26 · 62LAN C/27 · 30freeRouter link /30 (2 hosts).0.128.192.224.255Sort requirements from largest to smallest, then allocate each the smallest block that fits100 hosts → /25 (126) · 50 → /26 (62) · 20 → /27 (30) · 2 → /30 (2)
VLSM plan for 192.168.5.0/24: each subnet is just big enough, largest first, leaving space for future growth

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 neededHost bitsPrefix
2/30
6/29
14/28
30/27
62/26
126/25
254/24

Default gateway in practice

Every host needs:

  1. Its own IP address inside the usable range.
  2. The correct subnet mask (same as the rest of the subnet).
  3. The default gateway = the router's interface address on this subnet (also inside the usable range, often .1 by convention).
  4. 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.