Subnet mask and CIDR: how to calculate hosts and ranges
A /24 network has 256 addresses, but room for only 254 devices. A /30 has 4 and serves 2. Behind those sums is one short rule which, once understood, lets you work out the network, broadcast and range of any subnet by hand without memorising tables. The rule, with worked examples and the special cases.
What the mask is and what the prefix is
An IPv4 address is 32 bits, written as four groups of 8 (192.168.1.10). The subnet mask says how many of those 32 bits identify the network and how many identify the device inside it. It is written with ones for the network part and zeros for the device part: 24 ones followed by 8 zeros give 255.255.255.0.
CIDR notation (for “Classless Inter-Domain Routing”, described in RFC 4632) simply counts those ones and puts them after a slash: /24. They are two ways of saying the same thing: 192.168.1.0/24 is 192.168.1.0 with mask 255.255.255.0. The bigger the number after the slash, the smaller the network.
The sum that solves everything
With a prefix /n, 32 − n bits are left for devices. So:
- Addresses in the subnet = 2(32 − n).
- Usable hosts = 2(32 − n) − 2, because the first address identifies the network and the last is the broadcast address, and neither is assigned to a device.
For a /24: 28 = 256 addresses, 254 for devices. For a /26: 26 = 64 addresses, 62 usable.
| Prefix | Mask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (special case) |
| /32 | 255.255.255.255 | 1 | 1 (a single host) |
The last two are exceptions to the minus-2 rule. A /31 is used on point-to-point links between two routers: RFC 3021 allows both of its addresses to be used without reserving network or broadcast, halving the space spent per link. A /32 identifies a single host, common in routes and specific rules.
How to work out a subnet by hand
The trick is the “interesting” octet, the first one in the mask that is neither 255 nor 0. That octet sets the block size: 256 minus the mask's value in that octet.
Example 1: 192.168.1.130/26. The mask is 255.255.255.192, so the interesting octet is the fourth and the block is 256 − 192 = 64 wide. Subnets start at 0, 64, 128, 192. The 130 falls in the block starting at 128, so:
- Network:
192.168.1.128 - Broadcast:
192.168.1.191(the next block starts at 192, and the broadcast is the address just before) - Hosts:
192.168.1.129to192.168.1.190, 62 in all
Example 2: 172.20.5.77/20. The mask is 255.255.240.0: the interesting octet is the third and the block is 256 − 240 = 16 wide. Blocks start at 0, 16, 32… and the 5 falls in the one starting at 0:
- Network:
172.20.0.0 - Broadcast:
172.20.15.255 - Hosts:
172.20.0.1to172.20.15.254, 4,094 in all
If you want to check it, or need to convert between binary and decimal to understand the octets, the binary, decimal and hex converter is handy for seeing the ones and zeros in each octet.
Splitting a network into subnets
To split 192.168.1.0/24 into four equal subnets you need 2 more prefix bits (22 = 4), that is, four /26 networks of 62 hosts each: 192.168.1.0/26, 192.168.1.64/26, 192.168.1.128/26 and 192.168.1.192/26. To choose the right prefix, work out how many hosts you need plus 2 and find the smallest power of 2 that covers it: 50 hosts → 52 → 64 → /26; 100 hosts → 102 → 128 → /25. Always leave room to grow.
Private addresses and other reserved ranges
RFC 1918 reserves three ranges for private networks, which are not routed on the Internet:
10.0.0.0/8: from 10.0.0.0 to 10.255.255.255.172.16.0.0/12: from 172.16.0.0 to 172.31.255.255. This is where the commonest error lives: it is not all of 172.x, only 16 to 31.192.168.0.0/16: from 192.168.0.0 to 192.168.255.255, the one nearly every home router uses.
Also: 127.0.0.0/8 is the host's own internal loopback (127.0.0.1), per RFC 1122; 169.254.0.0/16 is the link-local range a device gives itself when it cannot get an address by DHCP (RFC 3927), which is why a 169.254.x.x address on a machine normally means it did not find a DHCP server; and 100.64.0.0/10 is the shared address space operators use for CGNAT (RFC 6598).
Wildcard mask
Some network equipment (access control lists, routing protocols) asks for the wildcard mask, which is the mask with its bits flipped: 255.255.255.255 minus the mask. For /24 it is 0.0.0.255; for /26, 0.0.0.63.
And in IPv6
IPv6 has no broadcast (RFC 4291 says so explicitly, with multicast addresses taking over its functions), so there is nothing to subtract. The usual subnet is a /64: RFC 4291 states that interface identifiers for unicast addresses are 64 bits long.
Calculating it without the sums
The IP subnet calculator gives you, from an address with a prefix or mask, the network, broadcast, wildcard, usable range and how many hosts fit, for IPv6 prefixes too. It runs in your browser, with no address sent to a server.
Sources and further reading
- RFC 4632: Classless Inter-domain Routing (CIDR)
- RFC 1918: Address Allocation for Private Internets
- RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links
- RFC 1122: Requirements for Internet Hosts (loopback 127.x.x.x)
- RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses
- RFC 6598: IANA-Reserved IPv4 Prefix for Shared Address Space
- RFC 4291: IP Version 6 Addressing Architecture
Figures checked on 3 October 2026.
Do it now, free, in your browser. Your files are not uploaded.
Network, mask, broadcast and host range from an IP address and prefix.
Frequently asked questions
What does /24 mean in an IP address?
Why does a /24 network hold 254 hosts and not 256?
How many hosts fit in a /26?
What are the private IP address ranges?
What is a 255.255.255.192 mask?
Why does a machine have an IP starting with 169.254?
Related guides
Tools used in this guide
They run in your browser, so nothing is uploaded.