hop 13 of 32 · 6 min
Subnetting, worked properly
A college is given 172.16.0.0/22 and four departments to fit into it. This is the calculation exams are built around, and it is entirely mechanical once you do it in the right order.
How big is the block
A /22 leaves 32 minus 22 = 10 host bits, so 2^10 = 1024 addresses, 1022 usable.
The departments
| Department | Hosts needed |
|---|---|
| CSE | 500 |
| ECE | 250 |
| Mechanical | 100 |
| Admin | 50 |
Total 900. It fits, but only just, and only if each subnet is sized properly.
Size each one first
Hosts plus 2, rounded up to a power of two:
| Dept | Needs | Plus 2 | Power of 2 | Host bits | Prefix | Usable |
|---|---|---|---|---|---|---|
| CSE | 500 | 502 | 512 | 9 | /23 | 510 |
| ECE | 250 | 252 | 256 | 8 | /24 | 254 |
| Mech | 100 | 102 | 128 | 7 | /25 | 126 |
| Admin | 50 | 52 | 64 | 6 | /26 | 62 |
Lay them out largest first
| Dept | Prefix | Range |
|---|---|---|
| CSE | 172.16.0.0/23 | 172.16.0.0 to 172.16.1.255 |
| ECE | 172.16.2.0/24 | 172.16.2.0 to 172.16.2.255 |
| Mech | 172.16.3.0/25 | 172.16.3.0 to 172.16.3.127 |
| Admin | 172.16.3.128/26 | 172.16.3.128 to 172.16.3.191 |
The block ends at 172.16.3.255, so 64 addresses are left over. Rounding every department up to a whole /24 would have needed a /21, twice the space.
This is VLSM, variable length subnet masking: different sized subnets in one block. Always allocate largest first, or you strand gaps too small to use.