Reconciling an IPv4 mask with the remaining address bits
An IPv4 prefix length, its dotted mask and the number of addresses in a block describe one fact three ways. This guide shows how to move between them using the count of bits left over.
Three views of one block size
An IPv4 address has 32 bits. A prefix of p fixes the first p of them and leaves 32 - p free. The block then holds 2^(32 - p) addresses, and the dotted mask has ones in the first p positions. For p = 26, six bits are free, the block holds 2^6 = 64 addresses, and the mask is 255.255.255.192. For p = 27, five bits are free, giving 32 addresses and the mask 255.255.255.224. Any one of the three values determines the other two, so a mismatch between them in a document flags a transcription error somewhere. A documented plan that lists 255.255.255.192 beside a block of 32 addresses, for example, contradicts itself, because that mask belongs to blocks of 64. Reconciling the three values row by row is a quick audit for an address plan, and it needs no tool beyond the bit count of 32 minus the prefix.
Reading the last mask octet
When the prefix falls inside the last octet, only that octet differs from 255. Its value is 256 minus the block size in that octet. With 64 addresses per block the octet is 256 - 64 = 192. With 32 addresses it is 224, and with 128 it is 128. The complete series for prefixes 25 to 32 is 128, 192, 224, 240, 248, 252, 254 and 255, with block sizes 128, 64, 32, 16, 8, 4, 2 and 1. This pattern lets you move between prefix and mask in your head, which is handy when a router configuration shows one form and an address plan shows the other.
Prefixes that fall in other octets
The same rule applies one octet earlier. A prefix of 20 fixes two full octets and four bits of the third, so the mask is 255.255.240.0. The third octet is 256 - 16 = 240, since the four free bits of that octet give 16 values. The block holds 2^12 = 4,096 addresses. A prefix of 22 gives 255.255.252.0 and 1,024 addresses, and a prefix of 24 gives 255.255.255.0 and 256. The cidr calculator returns the mask for any prefix you enter, so you can verify each of these in seconds.
One more bit halves the block
Moving from /26 to /27 fixes one more bit, so each block splits into two equal halves of 32. The mask changes from 192 to 224 in the last octet, which adds the next bit, worth 32. Going from /27 to /28 gives blocks of 16 and the octet 240. In the other direction, shortening the prefix by one doubles the block. So 192.0.2.0/27 holds 32 addresses, and the block 192.0.2.0/26 holds both it and 192.0.2.32/27. The subnet calculator reports 32 total addresses for 192.0.2.0 with prefix 27, and 4 for prefix 30.
Wildcard and inverse masks
Some systems, access lists among them, use a wildcard mask, which is the bitwise inverse of the netmask. For prefix 26 the netmask is 255.255.255.192 and the wildcard is 0.0.0.63. The wildcard value equals the block size minus one in the last octet, so it also gives the offset from the network address to the last address in the block. Not every wildcard in such systems has to be contiguous, but a netmask for a prefix always is. A contiguous mask is a run of ones followed by zeros, and the converter that maps a mask back to a prefix accepts only that form.
Masks that are not valid prefixes
A mask like 255.255.255.100 is not contiguous. In binary, 100 is 01100100, which has ones separated by zeros, so no prefix length produces it. Likewise 255.0.255.0 interleaves ones and zeros. The inverse conversion rejects these values rather than guessing. When you encounter such a mask in a document, one of its octets was probably mistyped or the value is a wildcard pattern from a different context. Compare each octet with the list of valid values 0, 128, 192, 224, 240, 248, 252, 254 and 255, and remember that after the first octet below 255 every later octet must be 0.
Usable hosts and the special cases
Under the usual convention, the lowest address of a block names the network and the highest is the broadcast address, so a /26 offers 62 host addresses out of 64. A /30 gives 2 out of 4, which fits a link between two routers. Two small blocks differ: a /31 has two addresses and may be used on point-to-point links under RFC 3021, and a /32 names a single address. The address count from the prefix arithmetic stays valid in every case, while the usable-host figure depends on the convention. For the two prefixes in this guide the conventional figures are 62 for /26 and 30 for /27, each two fewer than the address count. Keep the two numbers labeled separately in any table, since a reader who sees 64 beside 62 should be able to tell which is the block size and which is the host figure. This page reports the count only, so it needs no such rule.
Why not infer a class from the first octet
Older texts describe classes A, B and C, where the first octet implied the mask. Classless addressing, specified in RFC 4632, replaced this scheme, so the prefix must be given explicitly. The address 192.0.2.0 can carry a prefix of 24, 26 or 30, and the block size changes with each. Reading a /26 from the first octet alone would be a guess. The controls here use documentation addresses from 192.0.2.0/24, reserved by RFC 5737, and the arithmetic performs no network access or configuration. Before using a prefix in a real plan, confirm it with the owner of the address space.
Splitting a block and checking the arithmetic
A useful consistency test is to split a block and add the pieces. The block 192.0.2.0/26 holds 64 addresses. Split it into /28 blocks and each holds 2^4 = 16, so there are 4 of them, and 4 × 16 = 64. Split it into /27 blocks and there are 2 of 32. In general, a split from prefix p to prefix q gives 2^(q - p) blocks of 2^(32 - q) addresses, and the product returns 2^(32 - p). If a plan lists blocks whose sizes do not add to the parent size, an entry is wrong, missing or overlapping. This works with nothing more than the bit counts on this page.
Reproduce the checks
Six remaining bits
Open the Cidr Calculator and enter:
- Prefix length
26
Expected output:
Mask
255.255.255.192The final mask octet fixes two more bits.
Five remaining bits
Open the Cidr Calculator and enter:
- Prefix length
27
Expected output:
Mask
255.255.255.224One additional prefix bit halves the block size.
Block-size check
Open the Subnet Calculator and enter:
- IP address
192.0.2.0- Prefix length
27
Expected output:
Total addresses
32The count follows from five unfixed bits.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08