Skip to content
Subnet Math

Subnet cheat sheet: the CIDR chart

Every IPv4 prefix length from /0 to /32 in one table: the subnet mask, the wildcard mask, how many addresses the subnet holds and how many of them are usable. Below the chart are the patterns that let you work any row out in your head.

IPv4 CIDR chart: /0 to /32

Prefix Subnet mask Wildcard Total addresses Usable hosts
/0 0.0.0.0 255.255.255.255 4,294,967,296 4,294,967,294
/1 128.0.0.0 127.255.255.255 2,147,483,648 2,147,483,646
/2 192.0.0.0 63.255.255.255 1,073,741,824 1,073,741,822
/3 224.0.0.0 31.255.255.255 536,870,912 536,870,910
/4 240.0.0.0 15.255.255.255 268,435,456 268,435,454
/5 248.0.0.0 7.255.255.255 134,217,728 134,217,726
/6 252.0.0.0 3.255.255.255 67,108,864 67,108,862
/7 254.0.0.0 1.255.255.255 33,554,432 33,554,430
/8 255.0.0.0 0.255.255.255 16,777,216 16,777,214
/9 255.128.0.0 0.127.255.255 8,388,608 8,388,606
/10 255.192.0.0 0.63.255.255 4,194,304 4,194,302
/11 255.224.0.0 0.31.255.255 2,097,152 2,097,150
/12 255.240.0.0 0.15.255.255 1,048,576 1,048,574
/13 255.248.0.0 0.7.255.255 524,288 524,286
/14 255.252.0.0 0.3.255.255 262,144 262,142
/15 255.254.0.0 0.1.255.255 131,072 131,070
/16 255.255.0.0 0.0.255.255 65,536 65,534
/17 255.255.128.0 0.0.127.255 32,768 32,766
/18 255.255.192.0 0.0.63.255 16,384 16,382
/19 255.255.224.0 0.0.31.255 8,192 8,190
/20 255.255.240.0 0.0.15.255 4,096 4,094
/21 255.255.248.0 0.0.7.255 2,048 2,046
/22 255.255.252.0 0.0.3.255 1,024 1,022
/23 255.255.254.0 0.0.1.255 512 510
/24 255.255.255.0 0.0.0.255 256 254
/25 255.255.255.128 0.0.0.127 128 126
/26 255.255.255.192 0.0.0.63 64 62
/27 255.255.255.224 0.0.0.31 32 30
/28 255.255.255.240 0.0.0.15 16 14
/29 255.255.255.248 0.0.0.7 8 6
/30 255.255.255.252 0.0.0.3 4 2
/31 255.255.255.254 0.0.0.1 2 2
/32 255.255.255.255 0.0.0.0 1 1

This is address arithmetic from the IPv4 and IPv6 standards. It shows how a block divides up; it does not plan, configure or protect a network.

The formula, with a worked example

How to read the chart

Each row is one prefix length. The prefix is the number after the slash in CIDR notation, such as the 24 in 192.168.1.0/24, and it counts the network bits. The subnet mask column writes those bits as a dotted mask, the wildcard column flips them, the total column gives the size of the block and the usable column takes away the network and broadcast addresses.

The most common rows are /24 (255.255.255.0, 256 addresses, 254 usable), /16 (255.255.0.0, 65,536 addresses) and /8 (255.0.0.0, 16,777,216 addresses), which line up with whole octets. Between them sit the prefixes that split an octet, such as /20, /26 and /30, and those are the ones worth learning the patterns for.

The eight mask values

A mask is a run of ones then zeros, so inside any one octet the mask can only take nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Those come from adding the bit values 128, 64, 32, 16, 8, 4, 2 and 1 from the left. One network bit gives 128, two give 128 + 64 = 192, three give 224, and so on up to eight, which gives 255.

That is why the chart repeats itself every eight rows. /17, /25 and /9 all end their mask on 128 in a different octet; /18, /26 and /10 all end on 192. Learn the sequence 128, 192, 224, 240, 248, 252, 254, 255 once and you can write the mask for any prefix: fill whole octets with 255, then take the value from the sequence for the leftover bits.

Block sizes and the powers of two

Every step from one prefix to the next shorter one doubles the block. A /30 has 4 addresses, a /29 has 8, a /28 has 16, a /27 has 32, a /26 has 64, a /25 has 128 and a /24 has 256. Going the other way halves it. So the total for any prefix is 2 raised to the number of host bits, 32 minus the prefix.

In the octet where the mask stops being 255, the block size is 256 minus the mask value. For /26 the mask ends in 192, so the block size is 64 and the subnets start at .0, .64, .128 and .192. For /21 the mask is 255.255.248.0, so the block size in the third octet is 8 and the networks start at 0, 8, 16, 24 and so on in that octet.

Edge cases at both ends of the chart

The usable count is the total minus 2 for every prefix up to /30, which leaves 2 hosts. A /31 would leave none under that rule, so RFC 3021 lets both of its addresses be used on a point-to-point link and the chart shows 2. A /32 is one address on its own and shows 1.

At the top, /0 has a mask of 0.0.0.0 and covers all 4,294,967,296 IPv4 addresses. Prefixes from /1 to /7 are bigger than any normal allocation and appear mostly in routing tables, where they describe large slices of the whole address space.

Reading the wildcard column

The wildcard mask is the subnet mask with every bit flipped, so each octet of the wildcard is 255 minus the same octet of the mask. A /24 mask of 255.255.255.0 gives a wildcard of 0.0.0.255, and a /27 mask of 255.255.255.224 gives 0.0.0.31. The last octet of the wildcard is always one less than the block size in that octet, which makes it a quick check on the rest of the row.

The prefixes people look up most

Prefix Subnet mask Wildcard Total addresses Usable hosts
/8 255.0.0.0 0.255.255.255 16,777,216 16,777,214
/16 255.255.0.0 0.0.255.255 65,536 65,534
/24 255.255.255.0 0.0.0.255 256 254
/25 255.255.255.128 0.0.0.127 128 126
/26 255.255.255.192 0.0.0.63 64 62
/27 255.255.255.224 0.0.0.31 32 30
/28 255.255.255.240 0.0.0.15 16 14
/29 255.255.255.248 0.0.0.7 8 6
/30 255.255.255.252 0.0.0.3 4 2

Frequently asked questions

What is the subnet mask for /24, /16 and /8?

/24 is 255.255.255.0, /16 is 255.255.0.0 and /8 is 255.0.0.0. Each one fills whole octets with 255.

How many hosts are in a /26?

A /26 has 64 addresses and 62 usable hosts. Its mask is 255.255.255.192 and its wildcard is 0.0.0.63.

How many hosts are in a /30?

A /30 has 4 addresses and 2 usable hosts, with a mask of 255.255.255.252.

How many hosts are in a /29?

A /29 has 8 addresses and 6 usable hosts, with a mask of 255.255.255.248.

What is the mask for /20?

255.255.240.0. That is 16 ones for the first two octets and 4 more in the third (128 + 64 + 32 + 16 = 240). A /20 holds 4,096 addresses, 4,094 usable.

Why does a /31 show 2 usable hosts?

RFC 3021 allows both addresses of a /31 to be used on a point-to-point link, because such a link has no need for separate network and broadcast addresses.

Have a specific address? The IPv4 subnet calculator works out its network, broadcast and host range from any prefix in this chart. IPv4 subnet calculator

Other subnet tools on this site