- A prefix like /26 means the first 26 bits are the network and the remaining 6 are hosts.
- Network address = IP address AND subnet mask.
- Block size = 256 minus the mask value in the interesting octet.
- Usable hosts = 2host bits minus 2, except /31 and /32.
Network, host range, broadcast, mask and wildcard for any IPv4 block
What a subnet mask really says
An IPv4 address is 32 bits, written as four decimal octets. A subnet mask is another 32 bits that splits the address into two parts. Every 1 in the mask marks a network bit and every 0 marks a host bit. The ones always come first, so a mask can be written as a count of ones: 255.255.255.192 is 26 ones followed by 6 zeros, which is why we call it a /26.
Everything else follows from that split. Hosts that share the same network bits are on the same subnet and can talk directly. The host bits number the devices inside it. With 6 host bits there are 26 = 64 addresses in the block.
| Prefix | Mask | Network bits | Host bits | Addresses |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 24 | 8 | 256 |
| /26 | 255.255.255.192 | 26 | 6 | 64 |
| /20 | 255.255.240.0 | 20 | 12 | 4,096 |
| /29 | 255.255.255.248 | 29 | 3 | 8 |
Method 1: the binary AND
This is the method behind every calculator, including ours. Take 192.168.10.77/26.
- Write the address in binary:
11000000.10101000.00001010.01001101. - Write the /26 mask in binary:
11111111.11111111.11111111.11000000. - AND them bit by bit. A bit survives only where both are 1:
11000000.10101000.00001010.01000000. - Convert back to decimal. The network address is 192.168.10.64.
- Now set all six host bits to 1:
…01111111. That is the broadcast, 192.168.10.127.
The usable hosts are everything between: 192.168.10.65 to 192.168.10.126, which is 62 addresses. The binary method is slow, but it is the proof. When the shortcut gives an answer that looks odd, come back to it.
Method 2: the block-size shortcut
Most people subnet in their head with the block size, also called the magic number.
- Find the interesting octet: the one where the mask is neither 255 nor 0. For /26 that is the fourth octet, where the mask is 192.
- Block size = 256 − 192 = 64. Subnets in that octet start at 0, 64, 128 and 192.
- Find the multiple of 64 at or below the address value, 77. That is 64, so the network is 192.168.10.64.
- The next subnet starts at 128, so the broadcast is one less: 192.168.10.127.
Worked example: a /20
Find the network and broadcast for 172.20.141.9/20.
- /20 is 255.255.240.0, so the interesting octet is the third.
- Block size = 256 − 240 = 16. Multiples of 16: 128, 144... The largest at or below 141 is 128.
- Network: 172.20.128.0. The next block starts at 144, so the broadcast is 172.20.143.255.
- Hosts: 172.20.128.1 to 172.20.143.254, that is 212 − 2 = 4,094 usable.
Check it in the calculator with this address loaded.
Worked example: a /29
Find the usable range for 10.33.7.203/29.
- /29 is 255.255.255.248. Block size = 8.
- Multiples of 8 near 203: 200 and 208. The network is 10.33.7.200.
- Broadcast: 10.33.7.207. Usable hosts: .201 to .206, which is 6 hosts.
How many subnets and hosts
When you split a network you borrow host bits for the subnet number. Borrowing n bits gives 2n subnets, and every borrowed bit halves the hosts in each one.
| Split a /24 into | New prefix | Bits borrowed | Usable hosts each |
|---|---|---|---|
| 2 subnets | /25 | 1 | 126 |
| 4 subnets | /26 | 2 | 62 |
| 8 subnets | /27 | 3 | 30 |
| 16 subnets | /28 | 4 | 14 |
| 64 subnets | /30 | 6 | 2 |
To fit a host count instead, add 2 for the network and broadcast and round up to a power of two. 50 hosts need 52 addresses, which rounds up to 64, so a /26. When subnets need different sizes, use VLSM.
Mistakes that cost marks
- Using the wrong octet. A /20 changes the third octet, not the fourth. Always find where the mask stops being 255 first.
- Forgetting the minus two. A /27 has 32 addresses but only 30 usable hosts.
- Treating /31 as unusable. Since RFC 3021 a /31 holds two usable addresses on point-to-point links. See our /31 guide.
- Off-by-one on the broadcast. The broadcast is the next network minus one, never the next network itself.
- Classful thinking. 10.1.2.3/24 is a valid subnet even though 10.x was class A. Classes stopped mattering with CIDR in 1993.
The fastest way to get reliable is repetition. Try twenty questions in subnetting practice, where each wrong answer shows these same steps.
Sources
- RFC 950: Internet Standard Subnetting Procedure
- RFC 4632: Classless Inter-domain Routing (CIDR)
- RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links