Ranges and blocks
A CIDR block is a prefix and a length: 10.0.0.0/16 is every address that shares the first 16 bits with 10.0.0.0, 65,536 addresses in all. A block always holds a power of two addresses and always starts on a multiple of its own size, so most ranges (say, .10 to .130) aren't one block. They split into several.
Formula
- Block size
- 2(32 − prefix)
- Last address
- first + size − 1
- Aligned
- first is a multiple of size
- Range → blocks
- largest aligned block from the start that fits; repeat
Taking the largest block that starts at the current address and doesn't pass the end gives the fewest blocks. A range of IPv4 addresses never needs more than 62.
Worked example
The range 192.0.2.0 – 192.0.2.130. Start at 192.0.2.0: the largest block that starts there and stays inside the range is 192.0.2.0/25 (128 addresses, .0 to .127). The next address is 192.0.2.128, and so on until the end of the range:
192.0.2.0/25: 192.0.2.0 – 192.0.2.127, 128 addresses192.0.2.128/31: 192.0.2.128 – 192.0.2.129, 2 addresses192.0.2.130/32: 192.0.2.130, 1 address
3 blocks in all. No two can be joined: a block twice the size would either start before the range or run past its end.
Merging a list
To shrink a list (a firewall rule set, a route table, an allow list), the calculator joins every entry that overlaps or touches another into one stretch of addresses, then splits each stretch into blocks as above. The result covers exactly the same addresses with the fewest blocks. Two neighbouring blocks only join when they line up: 10.0.0.0/24 and 10.0.1.0/24 make 10.0.0.0/23, but 10.0.1.0/24 and 10.0.2.0/24 stay two blocks, because the /23 that would hold them both has to start at an even third octet.
The default list merges into 6 blocks. Entry #2 disappears into entry #1, and the two 192.168 entries touch but stay separate: joining them would take a block that also covers addresses the list doesn't.
Overlaps
Two CIDR blocks can never partly overlap: either they are separate, or the smaller one sits entirely inside the larger. Ranges can overlap partway, so the calculator reports three cases: the same addresses, one entry inside another, and a partial overlap with the shared addresses listed. Entries that only touch (one ends where the next begins) don't overlap.
IPv6
IPv6 entries work the same way and can sit in the same list: a prefix like 2001:db8::/48, a range, or a single address (a /128). IPv6 has no dotted masks. IPv4 and IPv6 entries are merged and compared only with their own kind. RFC 8215 gives an example of a range that takes two blocks: 64:ff9a:ffff:: – 64:ff9b::255.255.255.255 is 64:ff9a:ffff::/48 plus 64:ff9b::/96.
References
- RFC 4632, Classless Inter-domain Routing (CIDR): prefix notation, block sizes, aggregation.
- RFC 1918, Address Allocation for Private Internets: ranges written both as start–end and as prefixes.
- RFC 4291, IP Version 6 Addressing Architecture; RFC 5952, IPv6 address text representation; RFC 8215 §4.2.
- Published range splits and merges used to check the results: Python ipaddress (summarize_address_range, collapse_addresses), netaddr, Rust ipnet and Go netipx documentation; Cisco Press route-summarization examples.