Subnetting cheat sheet: prefix, mask, and host counts
The whole of IPv4 subnetting comes down to one idea: the prefix length tells you how many bits are fixed for the network, and everything left over addresses hosts. Once that clicks, the mask and the host count both fall out of simple arithmetic. This is the table and the mental math to get there.
The core table
A /n prefix fixes n bits for the network and leaves 32 - n bits for hosts. The number of addresses in the block is 2^(32 - n).
| Prefix | Mask | Addresses | Usable hosts |
|---|---|---|---|
/24 | 255.255.255.0 | 256 | 254 |
/25 | 255.255.255.128 | 128 | 126 |
/26 | 255.255.255.192 | 64 | 62 |
/27 | 255.255.255.224 | 32 | 30 |
/28 | 255.255.255.240 | 16 | 14 |
/29 | 255.255.255.248 | 8 | 6 |
/30 | 255.255.255.252 | 4 | 2 |
/31 | 255.255.255.254 | 2 | 2 |
Why usable is total minus two
In a normal subnet, two addresses are not assignable to hosts. The first, where all host bits are zero, is the network address, the name of the subnet itself. The last, where all host bits are one, is the broadcast address, which reaches every host at once. So usable hosts are 2^(32 - n) - 2. A /24 holds 256 addresses but only 254 go on machines.
The exception is /31. A point to point link between two routers has exactly two endpoints and no need for a broadcast, so RFC 3021 defines /31 to use both addresses as hosts. That is why the table shows /31 giving two usable hosts rather than zero.
Finding the network and broadcast addresses
For any address and prefix, the network address is the address with all host bits cleared to zero, and the broadcast is the same address with all host bits set to one. The quick way is to find the block size in the interesting octet.
The block size is 256 - (mask value in that octet). For a /26, the mask octet is 192, so the block size is 64. Subnets therefore start at .0, .64, .128, .192. An address of 192.168.1.100 with a /26 falls in the .64 block, because 100 sits between 64 and 127. So:
- Network address:
192.168.1.64 - Broadcast address:
192.168.1.127 - Usable range:
192.168.1.65to192.168.1.126
Mental math shortcuts
- Each step up in prefix halves the block and roughly halves the hosts. Each step down doubles them.
- Memorize the mask octet values:
128, 192, 224, 240, 248, 252, 254, 255. These correspond to one through eight bits borrowed. - The block size in the interesting octet is always
256minus that mask value, and valid subnet boundaries are multiples of the block size. - To size a subnet for
hhosts, find the smallest2^kthat is at leasth + 2, then the prefix is32 - k. Thirty hosts need 32 addresses, sok = 5and the prefix is/27.
A worked check
You need a subnet for 50 hosts. The smallest power of two at least 50 + 2 = 52 is 64, so k = 6 and the prefix is /26. That gives 62 usable hosts, enough with room to grow, and wastes fewer addresses than a /25 would.
To verify any of this against a real address, the Subnet Calculator returns the network, broadcast, mask, and usable range the moment you enter an IP and prefix.