The IP address of any computer belongs to a subnet: a range of IP addresses that can talk to each other over a Layer 2 (switching) network.
The size of this range can be written in several ways. For example, “255.255.255.0” and “/24” are two equivalent ways to write the same thing.
To understand what these numbers mean, though, first you’ll need to know binary. Good?
Comparing an IP address and subnet mask
Now, let’s look at an example IP address and subnet mask, each broken out by octet and then written in binary:
| Written as | Octet 1 | Octet 2 | Octet 3 | Octet 4 |
|---|---|---|---|---|
| IP address (decimal) | 192 | 168 | 0 | 1 |
| IP address (binary) | 11000000 | 10101000 | 00000000 | 00000001 |
| Subnet mask (decimal) | 255 | 255 | 255 | 0 |
| Subnet mask (binary) | 11111111 | 11111111 | 11111111 | 00000000 |
See how each octet lines up?
This IP address and subnet mask combination means that the subnet for 192.168.0.1 extends from 192.168.0.0 through 192.168.0.255. But why?
Network bits and host bits
The key is in the binary! Look at the subnet mask from above, 255.255.255.0, in binary:
11111111.11111111.11111111.00000000
Note that there are 32 bits in total: 8 for each octet (oct = 8). Reading from left to right, it has 1s until a certain point, and then 0s.
The bits with 1s are network bits, and the bits with 0s are host bits:
| Part | Value | Number of bits |
|---|---|---|
| Network bits | 11111111.11111111.11111111 | 24 |
| Host bits | 00000000 | 8 |
255.255.255.0 = /24
Every address in a subnet has the same network bits. With this subnet mask, the only thing that can vary is the last 8 bits, from 00000000 (0) to 11111111 (255).
Network and broadcast addresses
Two addresses in most subnets have special jobs, so they can’t be given to a computer:
- Network address: all of the host bits are 0. This is the first address, and it identifies the subnet itself.
- Broadcast address: all of the host bits are 1. This is the last address, and it reaches every device in the subnet.
Everything in between can be assigned to devices. To count the usable addresses, raise 2 to the number of host bits, then subtract these two special addresses. A /24 has 8 host bits:
2⁸ − 2 = 256 − 2 = 254 usable addresses
There are two exceptions. A /31 has only two addresses, and both can be used on a link between two devices. A /32 is a single address.
When the mask splits an octet
A /24 is easy to read because the network bits end exactly where the third octet ends. That isn’t always true. Let’s find the subnet for 192.168.1.130/26.
A /26 has 26 network bits, which leaves 32 − 26 = 6 host bits. The first three octets use 24 network bits, so the last octet has 2 network bits (in bold) and 6 host bits:
| Address | Last octet (binary) | Last octet (decimal) |
|---|---|---|
| IP address | 10000010 | 130 |
| Subnet mask | 11000000 | 192 |
| Network address (host bits all 0) | 10000000 | 128 |
| Broadcast address (host bits all 1) | 10111111 | 191 |
The network bits stay the same, and only the host bits change. So:
- Subnet mask: 255.255.255.192
- Network address: 192.168.1.128
- Broadcast address: 192.168.1.191
- Usable addresses: 192.168.1.129 through 192.168.1.190
- Number of usable addresses: 2⁶ − 2 = 62
A shortcut: block size
Once the binary makes sense, there’s a faster way. Find the octet where the mask isn’t 255 or 0, and subtract the mask’s value in that octet from 256. The answer is the block size. Subnets start at multiples of the block size.
For a /26, the mask is 255.255.255.192, so the block size is 256 − 192 = 64. In the last octet, subnets start at 0, 64, 128 and 192. Since 130 falls between 128 and 191, its network address ends in 128. That’s the same answer we found in binary.
Here are some common subnet sizes. For all of these, the block size applies to the last octet:
| Prefix | Subnet mask | Host bits | Block size | Usable addresses |
|---|---|---|---|---|
| /25 | 255.255.255.128 | 7 | 128 | 126 |
| /26 | 255.255.255.192 | 6 | 64 | 62 |
| /27 | 255.255.255.224 | 5 | 32 | 30 |
| /28 | 255.255.255.240 | 4 | 16 | 14 |
| /29 | 255.255.255.248 | 3 | 8 | 6 |
| /30 | 255.255.255.252 | 2 | 4 | 2 |
Practice
For each address, find the subnet mask, network address, broadcast address and number of usable addresses. Try these before looking at the answers below:
- 10.0.5.77/27
- 172.16.20.200/28
- 192.168.10.5/22 (Hint: look at the third octet.)
Answers
| Address | Subnet mask | Network address | Broadcast address | Usable addresses |
|---|---|---|---|---|
| 10.0.5.77/27 | 255.255.255.224 | 10.0.5.64 | 10.0.5.95 | 30 |
| 172.16.20.200/28 | 255.255.255.240 | 172.16.20.192 | 172.16.20.207 | 14 |
| 192.168.10.5/22 | 255.255.252.0 | 192.168.8.0 | 192.168.11.255 | 1,022 |
For the last one, the mask splits the third octet. The block size is 256 − 252 = 4, so subnets start at multiples of 4 in that octet. The multiple of 4 at or just below 10 is 8, so the subnet starts at 192.168.8.0. The next one starts at 192.168.12.0, so this one ends just before it, at 192.168.11.255.
