ADDRESS AND STATISTICAL CHECKS

Covering an unaligned IPv4 range exactly

A run of consecutive IPv4 addresses is not always one CIDR block. This guide covers 192.0.2.1 through 192.0.2.6 with four entries and shows why a single larger block adds unwanted addresses.

A contiguous range that is not a block

A CIDR block has a power-of-two size and starts at a multiple of that size. The range 192.0.2.1 through 192.0.2.6 holds six addresses. Six is not a power of two, so no single block can match it. Even a block that starts at the right place would be the wrong size. A single entry that includes all six must be larger, and the smallest block that contains them is the /29 from 192.0.2.0 to 192.0.2.7, which has eight addresses. Two of them, .0 and .7, were never in the range. An exact cover has to use several smaller entries instead. This is a counting fact before it is a networking one. Powers of two are 1, 2, 4, 8 and so on, and six can only be written as a sum of them in a few ways, such as 4 + 2 or 2 + 2 + 1 + 1. Alignment then decides which of those splits is available at a given start, which is why this particular range needs four pieces and not two.

The four-entry cover

The converter returns 192.0.2.1/32, 192.0.2.2/31, 192.0.2.4/31 and 192.0.2.6/32. Read them in order. A /32 is one address, so the first entry covers .1. A /31 is two addresses, so 192.0.2.2/31 covers .2 and .3, and 192.0.2.4/31 covers .4 and .5. The last entry covers .6. Counting 1 + 2 + 2 + 1 gives six, the same as the inclusive count 6 - 1 + 1. The list covers each requested address exactly once and nothing else, which is what exact cover means.

How the greedy method chooses

At each step the converter takes the largest block that starts at the current address, fits its alignment and stays within the end. At .1, an odd start, only a single address qualifies, because every larger block starts at an even number. At .2, a block of four would run from .2 to .5, but four-address blocks must start at a multiple of 4, and 2 is not one. So the block is two addresses. At .4 a block of four would reach .7, past the end at .6, so it again takes two. At .6, only one address remains. Each choice is the largest that satisfies alignment and fit together.

Other short ranges

The starting point changes the cover. The range 192.0.2.0 through 192.0.2.6 also has seven addresses, but it starts at a multiple of 4, so the first block can be a /30: 192.0.2.0/30 covers .0 to .3, then 192.0.2.4/31 covers .4 and .5, and 192.0.2.6/32 covers .6. That is three entries. The range 192.0.2.5 through 192.0.2.10 has six addresses and needs four: 192.0.2.5/32, 192.0.2.6/31, 192.0.2.8/31 and 192.0.2.10/32. Two ranges of equal length can need different numbers of entries, depending on where they begin. Both ranges have the same size of six addresses, yet one starts at an odd address and takes four entries, while a range of six that began at a multiple of 4, such as 192.0.2.4 through 192.0.2.9, would need only a /30 and a /31. Alignment of the start matters as much as the length of the range.

The cost of the larger block

The /29 containing .1 through .6 spans 192.0.2.0 through 192.0.2.7. The subnet calculator reports a network of 192.0.2.0, a last address of 192.0.2.7 and 8 total addresses. Of those, 6 were requested and 2 were not, so a third of the requested count, 33 percent, is extra. Whether that matters depends on the use. A list that should cover only certain addresses, such as an allow list, would change meaning if it grew by two. A pool that is meant to hold at least six addresses might accept the larger block gladly.

Exact cover versus containing block

The two answers address different questions. An exact cover says which blocks together contain precisely these addresses. A containing block says what single block contains all of them, accepting extras. Both have uses. Listing entries one by one suits a configuration that must name only the requested addresses, while a summary route suits a table where a short list matters more than precision. The worksheet reports the arithmetic of both and takes no side. The decision depends on whether extra addresses cause harm, which depends on the setting. A useful habit is to write down the reason for the choice next to the entries. A note such as exact cover, extra addresses not acceptable tells the next reader why four lines were used instead of one, and prevents a later cleanup from merging them into the single /29 and widening the coverage by two addresses without anyone noticing the change.

Checking a cover by hand

Verify any cover with two tests. First, add the block sizes. Each /32 adds 1, each /31 adds 2, each /30 adds 4, and so on, and the sum must equal last minus first plus one. Second, check that every block starts at a multiple of its own size and that each block begins right after the previous one ends. For 192.0.2.5 through 192.0.2.10, the sizes are 1, 2, 2 and 1, which total 6, matching 10 - 5 + 1. The starts 5, 6, 8 and 10 are consistent: 6 is even, 8 is a multiple of 2, and the blocks touch end to start.

Why the number of entries matters

Each CIDR entry becomes a line in a firewall list, a route table or an address plan. Short lists are easier to review, and tools may limit how many entries a list can hold. Choosing a start that is a multiple of a large power of two reduces the entries needed. For this reason, allocations are made on aligned boundaries, and ranges that begin at odd addresses tend to be fragmented. The worksheet makes the cost visible: a six-address range can take anywhere from two to four entries depending on where it begins.

What the result is and is not

The output is a mathematical list of address blocks. It is not a routing or filtering recommendation, and it does not say that the addresses are assigned or reachable. The examples use the documentation range 192.0.2.0/24 reserved by RFC 5737, so they point at no real network. When applying a cover to real equipment, confirm the addresses with the owner of the space, and test the resulting entries in the system that will use them.

Reproduce the checks

Exact six-address cover

Open the Ipv4 Range To Cidr Calculator and enter:

Start
192.0.2.1
End
192.0.2.6

Expected output:

Blocks

192.0.2.1/32
192.0.2.2/31
192.0.2.4/31
192.0.2.6/32

The fragments cover only the requested values.

Larger containing block

Open the Subnet Calculator and enter:

IP address
192.0.2.1
Prefix length
29

Expected output:

Network

192.0.2.0

Last address

192.0.2.7

Total addresses

8

This block includes two addresses outside the requested range.

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

Related tasks