Two ways to write the same boundary

A subnet boundary can be written as a prefix length, such as /20, or as a mask, such as 255.255.240.0. Router configuration, cloud consoles and documentation use one or the other, and moving between them by hand invites mistakes. Enter 20 here and the mask is 255.255.240.0. The prefix is simply the count of leading one bits, so a /20 mask has 20 ones followed by 12 zeros. Because the two forms carry identical information, record the prefix alongside any address you save, since the address alone does not say where the network part ends. Many tools accept either form, but some accept only one, so being able to translate quickly saves trips to the documentation.

How the prefix becomes four numbers

Write n ones followed by 32 − n zeros, then split into four groups of eight bits and convert each group to decimal. For /20, the first two octets are all ones, 255 and 255. The third octet holds four ones and four zeros, 11110000 in binary, which is 240. The fourth is all zeros. The mask is therefore 255.255.240.0. A group with k leading ones has a value of 256 minus 2^(8−k): one leading one is 128, two give 192, three give 224, four give 240, five give 248, six give 252, seven give 254 and eight give 255. Memorizing that short list covers every mask.

Common prefixes and what they hold

A /24 mask is 255.255.255.0 and holds 256 addresses, the familiar size of a small office network. A /16 is 255.255.0.0 with 65,536 addresses. A /27 is 255.255.255.224 with 32 addresses, a /22 is 255.255.252.0 with 1,024, and a /30 is 255.255.255.252 with 4, as used on router-to-router links. The size of a block is 2^(32−prefix), so each extra prefix bit halves the block. At the ends, /0 gives 0.0.0.0, matching all addresses and used for default routes, while /32 gives 255.255.255.255 and identifies a single address. Those figures help you size networks before you open any tool.

Worked default and a second case

The default of 20 gives 255.255.240.0. The third octet is 240, so blocks are 16 wide in that octet, and the block size is 2^12 = 4,096 addresses. A network such as 172.16.0.0/20 therefore runs from 172.16.0.0 to 172.16.15.255, and the next /20 starts at 172.16.16.0. A second case: an organization needs room for 500 hosts. A /23 gives 512 addresses and about 510 usable, so its mask is 255.255.254.0. A /24 would be too small, with only 254 usable. Counting needed hosts, rounding up to the next power of two plus two reserved addresses, and reading off the prefix is the usual sizing routine.

Reading a mask back into a prefix

To go the other way by hand, add up the one bits in each octet. For 255.255.255.192 the first three octets contribute 24, and 192 is 11000000 in binary, which adds two more, so the prefix is 26. A valid mask is made of contiguous ones followed by contiguous zeros. A value such as 255.0.255.0 sets bits in a pattern no CIDR prefix can describe, and a mask like 255.255.255.250 breaks the pattern in the last octet, so neither converts to a prefix. Older equipment sometimes allowed such non-contiguous masks, but they are not valid in modern CIDR notation. If a mask looks wrong, check for a mistyped octet; every octet of a valid mask is one of 0, 128, 192, 224, 240, 248, 252, 254 or 255, and once an octet is less than 255 all later octets must be 0.

Wildcard masks and the inverse

Some router and firewall syntaxes, especially access lists on certain platforms, use a wildcard mask, which is the bitwise inverse of the subnet mask. For 255.255.240.0 the wildcard is 0.0.15.255. To derive it, subtract each mask octet from 255. This page does not display the wildcard, but you can compute it in a moment from the mask it returns. Confusing the two is a classic cause of access rules matching far more or far fewer addresses than intended, so check which form your device expects. A wildcard of all zeros means every bit must match exactly, which corresponds to a /32.

Why CIDR replaced classes

Before 1993, IPv4 networks were classes: A with an 8-bit prefix, B with 16 and C with 24, and the class came from the leading bits of the address. That wasted space, because an organization that needed 2,000 addresses had to take a class B of 65,536. Classless inter-domain routing, introduced in RFC 1518 and RFC 1519 and now specified in RFC 4632, let networks use any prefix length and let providers aggregate many routes into one. The notation address/prefix, as in 192.0.2.0/24, comes from that work. The size of the global routing table would be far larger today without aggregation.

Mistakes to watch for

Entering 255 where a prefix belongs, or reading 24 as a mask, swaps the two forms. A number above 32 is invalid for IPv4. Some people count the zero bits instead of the ones, treating a /20 as a /12. A related slip is to forget that a longer prefix means a smaller network, so /28 is smaller than /24. When subnetting a block, remember that every subnet needs its own boundary on a multiple of its size, and use the subnet calculators on this site for that step. This page only translates the mask; it does not check that an address belongs to any block.

Prefix range and whole-number rules for masks

The supported prefix range is 0 to 32 and the output is a standard IPv4 mask. Whole numbers only are meaningful here, since a prefix counts bits, and a fractional value has no mask. Prefix /31 and /32 convert normally, giving 255.255.255.254 and 255.255.255.255, even though other pages on this site treat those sizes as special cases for host counts. The page does not handle IPv6, where prefixes run to 128 and masks are not written in dotted form. It also does not tell you which addresses are usable, whether a block is public or private, or how to route it. Treat the answer as a translation of notation. For network planning, pair it with the sizes in the examples above and with the documentation of your equipment, because syntax for masks and wildcards differs between vendors.