IT & NETWORKING

IP Range to CIDR

Turn an IPv4 or IPv6 address range into the smallest exact list of CIDR blocks, or blocks back into ranges — several per line, merged, for firewall rules.

The minimal CIDR cover of each range with first and last address and size per block, the merged list across all inputs, the total address count, and the blocks as one copyable list.

Example: 192.168.1.10 – 192.168.1.100 needs seven blocks (/31, /30, /28, /27, /27, /30, /32); 10.0.0.0/25 + 10.0.0.128/25 merge into 10.0.0.0/24; 2001:db8::1 – ::ff is eight blocks.

v0.1.0 · last reviewed 22 September 2026
Loading the workspace…
BUILT TO BE UNDERSTOOD

Largest aligned block first,
until the range is covered.

How the cover is built, what merging does, and how IPv6 is handled.

The algorithm

From the start address, take the largest block whose size is a power of two, whose start is a multiple of that size (aligned) and whose end does not pass the range end; move to the address after it and repeat. This greedy walk gives the minimal exact cover — no smaller list of CIDR blocks covers the same addresses and nothing else. A range that starts and ends on block boundaries is one block; an arbitrary range needs up to two blocks per bit of address length.

Inputs and merging

Each line is a range (a − b, a to b), a CIDR block or a single address; a CIDR block typed with a host address (10.0.1.7/24) is read as its network and noted. All inputs are sorted and merged where they overlap or touch, then covered again, so two /25 halves become one /24 and a duplicate disappears. The per-input cover is shown too.

IPv6

IPv6 addresses are parsed with :: compression and written back in RFC 5952 canonical form (lower-case, longest zero run compressed); the arithmetic uses 128-bit integers. IPv4 and IPv6 cannot be mixed in one list. Nothing leaves the browser; the same four anonymous usage counts as the rest of the site apply.

SOURCES

  • Greedy cover: from the range start take the largest power-of-two block aligned to its size that does not pass the end, repeat; adjacent and overlapping inputs merged first; IPv6 per RFC 4291 / 5952

Last reviewed 22 September 2026. How results are checked: How we verify.