How to calculate a subnet
An IPv4 address is 32 bits, written as four numbers from 0 to 255. The prefix says how many of those bits, from the left, are the network; the rest number the devices. Line the address up with the mask in binary and three things follow:
Here it is with your numbers:
- /24 means the first 24 of the 32 bits are the network, so the mask is 11111111.11111111.11111111.00000000, which is 255.255.255.0.
- Keep the address’s bits where the mask has a 1 (a bitwise AND): 192.168.1.10 gives the network address 192.168.1.0.
- Turn the other 8 bits on (OR with the wildcard 0.0.0.255) for the broadcast address, 192.168.1.255.
- 2⁸ is 256 addresses; take away the network and broadcast addresses: 256 − 2 = 254 usable hosts.
It means devices on 192.168.1.0/24 can use the addresses 192.168.1.1 – 192.168.1.254.
The host part may not be all 0s or all 1s: all 0s is the network’s own address and all 1s is its broadcast address, so they can’t be given to a device. That is where the “minus 2” comes from. A /31 is the exception: on a link between two routers both addresses are used.
Source RFC 4632 · Classless Inter-domain Routing (CIDR), §3.1 prefix notation ↗RFC 1122 · Requirements for Internet Hosts, §3.2.1.3 addressing ↗RFC 3021 · Using 31-Bit Prefixes on IPv4 Point-to-Point Links ↗
CIDR to subnet mask chart
Tap a prefix to see it worked out for 192.168.1.10.
| Prefix | Subnet mask | Usable hosts |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 |
| /9 | 255.128.0.0 | 8,388,606 |
| /10 | 255.192.0.0 | 4,194,302 |
| /11 | 255.224.0.0 | 2,097,150 |
| /12 | 255.240.0.0 | 1,048,574 |
| /13 | 255.248.0.0 | 524,286 |
| /14 | 255.252.0.0 | 262,142 |
| /15 | 255.254.0.0 | 131,070 |
| /16 | 255.255.0.0 | 65,534 |
| /17 | 255.255.128.0 | 32,766 |
| /18 | 255.255.192.0 | 16,382 |
| /19 | 255.255.224.0 | 8,190 |
| /20 | 255.255.240.0 | 4,094 |
| /21 | 255.255.248.0 | 2,046 |
| /22 | 255.255.252.0 | 1,022 |
| /23 | 255.255.254.0 | 510 |
| /24 | 255.255.255.0 | 254 |
| /25 | 255.255.255.128 | 126 |
| /26 | 255.255.255.192 | 62 |
| /27 | 255.255.255.224 | 30 |
| /28 | 255.255.255.240 | 14 |
| /29 | 255.255.255.248 | 6 |
| /30 | 255.255.255.252 | 2 |
| /31 | 255.255.255.254 | 2 |
| /32 | 255.255.255.255 | 1 |
Each block has 2 more addresses than usable hosts, for the network and broadcast addresses (except /31 and /32). Each step down the chart halves the network. The chart starts at /8, the size of block the Internet Assigned Numbers Authority (IANA) hands to the regional internet registries.
Private IP address ranges
Three blocks are set aside for private networks, such as the one behind your home router. They are never routed on the public internet, so every home can use the same ones:
| Block | Range |
|---|---|
| 10.0.0.0/8 | 10.0.0.0 – 10.255.255.255 |
| 172.16.0.0/12 | 172.16.0.0 – 172.31.255.255 |
| 192.168.0.0/16 | 192.168.0.0 – 192.168.255.255 |
Addresses starting 127 are loopback: they always mean “this computer” and never leave it.
Source RFC 1918 · Address Allocation for Private Internets, §3 ↗
FAQs
What is a subnet mask and why is it used?
A subnet mask marks which bits of an IPv4 address are the network and which are the device: 1s for the network, then 0s. 255.255.255.0 is 24 ones, so in 192.168.1.10 the network is 192.168.1 and the device is 10. Devices on the same network talk directly; anything else goes through a router.
Source RFC 4632 · Classless Inter-domain Routing (CIDR), §3.1 prefix notation ↗
Is CIDR the same as subnet mask?
They say the same thing two ways. The CIDR prefix counts the 1 bits (/24), and the mask writes them out as four numbers (255.255.255.0). /16 is 255.255.0.0, /20 is 255.255.240.0.
What is the subnet mask if the CIDR is 22?
/22 is 255.255.252.0: 22 ones, then 10 zeros. It holds 1,024 addresses, 1,022 of them usable by devices.
What is the subnet mask for a 30 CIDR?
/30 is 255.255.255.252: 4 addresses, 2 of them usable, the usual size for a link between two routers. A /31 (255.255.255.254) can do the same with 2 addresses and no waste.
Source RFC 3021 · Using 31-Bit Prefixes on IPv4 Point-to-Point Links ↗
How many hosts are in a 27 subnet?
A /27 has 32 addresses, so 30 usable hosts: the first is the network address and the last is the broadcast address.
Source RFC 1122 · Requirements for Internet Hosts, §3.2.1.3 addressing ↗
How many IP addresses are in a 25?
A /25 has 128 addresses (2 to the power of 7), and 126 of them can be given to devices.
How big is a 24 CIDR?
A /24 has 256 addresses and 254 usable hosts, such as 192.168.1.1 to 192.168.1.254, with 192.168.1.0 as the network and 192.168.1.255 as the broadcast address.
Is 255.255.0.0 a subnet mask?
Yes: it is /16, 16 ones then 16 zeros, for 65,536 addresses (65,534 usable). It was the mask of the old “Class B” networks.
Source RFC 4632 · Classless Inter-domain Routing (CIDR), §3.1 prefix notation ↗
Is 29 subnet 248?
Yes. /29 is 255.255.255.248: 29 ones leaves 3 zero bits, and 256 − 8 is 248. It has 8 addresses and 6 usable hosts.
Sources
- RFC 4632: Classless Inter-domain Routing (CIDR), §3.1 prefix notation
- RFC 1122: Requirements for Internet Hosts, §3.2.1.3 addressing
- RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links
- RFC 1918: Address Allocation for Private Internets, §3