Subnet Mask Cheat Sheet
The conversions and mental arithmetic used daily. For the complete table including host counts and every prefix length, see the CIDR chart.
The eight octet values
Every subnet mask octet is one of nine values. Memorising the eight non-trivial ones removes the need to look anything up.
| Octet value | Bits | Block size | Binary |
|---|---|---|---|
| 128 | 1 | 128 | 10000000 |
| 192 | 2 | 64 | 11000000 |
| 224 | 3 | 32 | 11100000 |
| 240 | 4 | 16 | 11110000 |
| 248 | 5 | 8 | 11111000 |
| 252 | 6 | 4 | 11111100 |
| 254 | 7 | 2 | 11111110 |
| 255 | 8 | 1 | 11111111 |
Block size is always 256 โ octet value. That single relationship is the whole of the magic-number method below.
Mask to prefix, /16 to /32
The range people actually configure.
| Prefix | Subnet mask | Addresses | Usable | Subnets per /24 |
|---|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,534 | โ |
| /17 | 255.255.128.0 | 32,768 | 32,766 | โ |
| /18 | 255.255.192.0 | 16,384 | 16,382 | โ |
| /19 | 255.255.224.0 | 8,192 | 8,190 | โ |
| /20 | 255.255.240.0 | 4,096 | 4,094 | โ |
| /21 | 255.255.248.0 | 2,048 | 2,046 | โ |
| /22 | 255.255.252.0 | 1,024 | 1,022 | โ |
| /23 | 255.255.254.0 | 512 | 510 | โ |
| /24 | 255.255.255.0 | 256 | 254 | 1 |
| /25 | 255.255.255.128 | 128 | 126 | 2 |
| /26 | 255.255.255.192 | 64 | 62 | 4 |
| /27 | 255.255.255.224 | 32 | 30 | 8 |
| /28 | 255.255.255.240 | 16 | 14 | 16 |
| /29 | 255.255.255.248 | 8 | 6 | 32 |
| /30 | 255.255.255.252 | 4 | 2 | 64 |
| /31 | 255.255.255.254 | 2 | 2 | 128 |
| /32 | 255.255.255.255 | 1 | 1 | 256 |
/31 and /32 are the exceptions to “usable equals total minus two”. A /31 is a point-to-point link under RFC 3021 with both addresses assignable; a /32 is a single host route.
Subnet boundaries by prefix
Where the networks start in the interesting octet.
| Prefix | Block size | Boundaries |
|---|---|---|
| /25 | 128 | 0, 128 |
| /26 | 64 | 0, 64, 128, 192 |
| /27 | 32 | 0, 32, 64, 96, 128, 160, 192, 224 |
| /28 | 16 | 0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240 |
| /29 | 8 | every 8 from 0 to 248 |
| /30 | 4 | every 4 from 0 to 252 |
The magic-number method
Working out which subnet an address belongs to, without a calculator.
1. Find the block size. Subtract the interesting octet of the mask from 256. For 255.255.255.192, that is 256 โ 192 = 64.
2. Count up in that increment. Boundaries are 0, 64, 128, 192.
3. Find the boundary at or below your address. That is the network address.
4. The broadcast is the next boundary minus one. Usable hosts sit between them.
Worked example for 10.1.1.100/26:
Mask 255.255.255.192
Block size 256 โ 192 = 64
Boundaries .0 .64 .128 .192
100 falls in .64 โ .127
Network 10.1.1.64
First host 10.1.1.65
Last host 10.1.1.126
Broadcast 10.1.1.127The same method works in any octet. For 172.20.36.5/18, the mask is 255.255.192.0, block size 64 in the third octet, boundaries 0, 64, 128, 192 โ so 36 falls in the first block and the network is 172.20.0.0/18.
Wildcard masks
The bitwise inverse of the netmask, used in Cisco ACLs and OSPF network statements. Subtract each octet from 255.
| Prefix | Subnet mask | Wildcard mask |
|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 |
| /25 | 255.255.255.128 | 0.0.0.127 |
| /26 | 255.255.255.192 | 0.0.0.63 |
| /27 | 255.255.255.224 | 0.0.0.31 |
| /28 | 255.255.255.240 | 0.0.0.15 |
| /29 | 255.255.255.248 | 0.0.0.7 |
| /30 | 255.255.255.252 | 0.0.0.3 |
A set bit in a wildcard mask means “ignore this bit when matching”, which is why the pattern looks inverted compared with everything else in a router configuration.
Related
- Subnet calculator โ check the arithmetic and split a block
- CIDR chart โ all prefix lengths, /0 to /32
- Address plan design โ choosing which prefix to use where
- Glossary โ terms used above