NETWORK
Subnet maskHow a mask splits network from host
A subnet mask is a 32-bit value that tells a device which part of an IPv4 address identifies the network and which part identifies the host. The mask 255.255.255.0 (written /24 in CIDR notation) means the first 24 bits are the network and the last 8 bits, 254 usable addresses, are for hosts.
What a subnet mask does
An IPv4 address such as 192.168.1.37 is really a 32-bit number. On its own it does not say how big the local network is. The subnet mask supplies that information: every bit set to 1 in the mask marks a network bit, every 0 marks a host bit.
Address 192.168.1.37 11000000.10101000.00000001.00100101
Mask 255.255.255.0 11111111.11111111.11111111.00000000
Network 192.168.1.0 11000000.10101000.00000001.00000000A device ANDs its own address with the mask to find its network, and does the same with any destination address. If the results match, the destination is local and can be reached directly (after an ARP lookup). If they differ, the packet goes to the default gateway.
Mask and prefix length are the same information
CIDR notation writes the number of 1 bits after a slash. Both forms appear in configuration screens and command output:
| Mask | Prefix | Addresses | Usable hosts |
|---|---|---|---|
| 255.0.0.0 | /8 | 16,777,216 | 16,777,214 |
| 255.255.0.0 | /16 | 65,536 | 65,534 |
| 255.255.255.0 | /24 | 256 | 254 |
| 255.255.255.128 | /25 | 128 | 126 |
| 255.255.255.192 | /26 | 64 | 62 |
| 255.255.255.224 | /27 | 32 | 30 |
| 255.255.255.240 | /28 | 16 | 14 |
| 255.255.255.248 | /29 | 8 | 6 |
| 255.255.255.252 | /30 | 4 | 2 |
| 255.255.255.254 | /31 | 2 | 2 (point-to-point) |
| 255.255.255.255 | /32 | 1 | 1 (single host route) |
See the CIDR notation record for the prefix side of this.
Working out a subnet by hand
For 10.20.30.77/27:
- /27 leaves 5 host bits, so each subnet has 2^5 = 32 addresses.
- Subnets start at multiples of 32 in the last octet: 0, 32, 64, 96…
- 77 falls in the 64–95 block.
- Network
10.20.30.64, broadcast10.20.30.95, usable10.20.30.65–10.20.30.94.
The Subnet Calculator shows the same steps with the binary highlighted.
Common mistakes
- Non-contiguous masks such as 255.255.0.255 are invalid; the ones must be a solid run from the left.
- Mask mismatch between two devices on the same wire is a classic fault: each thinks the other is on a different network and sends via the gateway, or cannot reach it at all.
- Confusing the mask with the gateway. The mask defines the local network's size; the gateway is a specific address inside it.
Where you see it on Windows
ipconfig shows Subnet Mask . . . : 255.255.255.0 under each adapter. route print shows the same information as a Netmask column in the routing table. See ipconfig and route.
Frequently asked questions
What does 255.255.255.0 mean?
The first three octets are all ones in binary (network bits) and the last is all zeros (host bits). Two addresses with the same first three octets are on the same subnet; the subnet holds 256 addresses of which 254 are usable.
How do I convert a mask to a prefix length?
Count the 1 bits. 255.255.255.0 has 24, so /24. 255.255.255.192 is 11000000 in the last octet, 26 ones in total, so /26. The Subnet Calculator does this instantly.
Why are two addresses subtracted from the host count?
The lowest address in the block (all host bits 0) identifies the network itself, and the highest (all host bits 1) is the broadcast address. Neither can be assigned to a device on a normal subnet. /31 point-to-point links are the exception.