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.

Reviewed on 3 October 2026 · 4 min read

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.

PrefixMaskAddressesUsable hosts
/8255.0.0.016,777,21616,777,214
/16255.255.0.065,53665,534
/20255.255.240.04,0964,094
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422 (special case)
/32255.255.255.25511 (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.129 to 192.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.1 to 172.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

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?
That the first 24 bits identify the network and the remaining 8 the hosts. It is the same as the mask 255.255.255.0 and leaves 256 addresses, of which 254 are usable.
Why does a /24 network hold 254 hosts and not 256?
Because the first address identifies the network and the last is the broadcast address, and neither is assigned to a device.
How many hosts fit in a /26?
62. A /26 has 64 addresses (2 to the power of 6), minus the network and broadcast addresses.
What are the private IP address ranges?
According to RFC 1918: 10.0.0.0/8, 172.16.0.0/12 (from 172.16.0.0 to 172.31.255.255) and 192.168.0.0/16.
What is a 255.255.255.192 mask?
The mask of a /26: 26 network bits and 6 host bits, that is, blocks of 64 addresses.
Why does a machine have an IP starting with 169.254?
Because it could not get an address by DHCP and assigned itself a link-local one (range 169.254.0.0/16), as described in RFC 3927.