What does a subnet mask mean?
An IP subnet mask separates the network part of an IP address from the host part. Written as four decimal numbers — 255.255.255.0 — it is really a 32-bit pattern of consecutive 1s followed by consecutive 0s. When a device combines the mask with an IP address using a bitwise AND, the result is the network address. Two devices are on the same subnet when they produce the same network address.
Subnet mask to CIDR
To convert a subnet mask to CIDR, count the 1 bits. Each full 255 octet contributes 8 bits, and partial octets contribute as follows: 128 = 1, 192 = 2, 224 = 3, 240 = 4, 248 = 5, 252 = 6, 254 = 7. So 255.255.255.224 is 8 + 8 + 8 + 3 = /27. Masks such as 255.0.255.0 are invalid because their 1 bits are not contiguous.
Subnet mask of class A, B and C
| Class | Default mask | CIDR | First octet |
|---|---|---|---|
| A | 255.0.0.0 | /8 | 1 – 126 |
| B | 255.255.0.0 | /16 | 128 – 191 |
| C | 255.255.255.0 | /24 | 192 – 223 |
Subnet mask list: /0 to /32
Every IPv4 prefix with its subnet mask, wildcard mask and number of usable hosts. Click a prefix on the cheat sheet for its dedicated page.
| CIDR | Subnet mask | Wildcard | Usable hosts |
|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,294 |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,646 |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,822 |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,910 |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,454 |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,726 |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,862 |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,430 |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,214 |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,606 |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,302 |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,150 |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,574 |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,286 |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,142 |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,070 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,534 |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,766 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,382 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,190 |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,094 |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,046 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,022 |
| /23 | 255.255.254.0 | 0.0.1.255 | 510 |
| /24 | 255.255.255.0 | 0.0.0.255 | 254 |
| /25 | 255.255.255.128 | 0.0.0.127 | 126 |
| /26 | 255.255.255.192 | 0.0.0.63 | 62 |
| /27 | 255.255.255.224 | 0.0.0.31 | 30 |
| /28 | 255.255.255.240 | 0.0.0.15 | 14 |
| /29 | 255.255.255.248 | 0.0.0.7 | 6 |
| /30 | 255.255.255.252 | 0.0.0.3 | 2 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 |
Subnet mask and the default gateway
Every host is configured with an IP address, a subnet mask and a default gateway. The mask tells the host which addresses are “local”. Anything outside the subnet is sent to the gateway, so the gateway must be inside the same subnet. If you enter a gateway that falls outside the range shown by the calculator, the host will not be able to reach it — one of the most common misconfigurations in small networks.