IP Range to CIDR Converter

Turn IP ranges into the fewest CIDR blocks, merge lists, and copy them as firewall rules.

Write a range as start - end (or "to"). IPv4 and IPv6; text after # is ignored. Results update as you type.

Result

5 CIDR blocks covering 16 addresses.

CIDR blockFirst addressLast addressAddresses
10.0.0.5/3210.0.0.510.0.0.51
10.0.0.6/3110.0.0.610.0.0.72
10.0.0.8/2910.0.0.810.0.0.158
10.0.0.16/3010.0.0.1610.0.0.194
10.0.0.20/3210.0.0.2010.0.0.201

How to Convert an IP Range to CIDR

An IP range rarely fits one CIDR block: 10.0.0.5–10.0.0.20 needs 10.0.0.5/32, 10.0.0.6/31, 10.0.0.8/29, 10.0.0.16/30 and 10.0.0.20/32. This tool finds the smallest set of blocks, or merges a whole list of ranges into firewall-ready CIDRs, for IPv4 and IPv6.

Start at the first address and take the largest block that starts there and doesn't pass the end; repeat from the next address. A block of 2n addresses can only start on a multiple of 2n:

Next addressLargest block that fitsCovers
10.0.0.5/32 (5 is odd)10.0.0.5
10.0.0.6/31 (2 addresses)10.0.0.6–10.0.0.7
10.0.0.8/29 (8 addresses)10.0.0.8–10.0.0.15
10.0.0.16/30 (4 addresses; a /29 would pass .20)10.0.0.16–10.0.0.19
10.0.0.20/3210.0.0.20

Merge Many Ranges Into CIDR Blocks

Paste ranges, CIDRs or single IPs; overlaps are merged and the result is the minimal list.

This is the job behind most allow-lists and block-lists: a provider's published ranges, a country list, or addresses collected from logs. Lines are sorted, overlapping and touching ranges are joined (10.0.0.0/25 and 10.0.0.128/25 become 10.0.0.0/24), and each merged range is split into the fewest aligned blocks. IPv4 and IPv6 can be mixed; lines that can't be read are listed with the reason instead of being guessed.

Use the Result in Firewall Rules

Copy the blocks as nginx, Apache, iptables or cloud security-group rules.

  • nginx: allow lines followed by deny all;, for a location or server block.
  • Apache 2.4: one Require ip line with every block.
  • iptables: ACCEPT rules, using ip6tables for IPv6 blocks.
  • nftables: named sets with flags interval, to use in a rule such as ip saddr @allowed_v4 accept.
  • AWS: a JSON permission list for aws ec2 authorize-security-group-ingress --ip-permissions; it opens TCP 443 by default, so edit the port first.

Review generated rules before applying them: an allow-list that's wider than intended is a security problem.

CIDR to IP Range

A CIDR block's range runs from its network address to the last address: 192.168.1.0/24 → 192.168.1.0–192.168.1.255.

Enter a single block, such as 10.0.0.0/22, and the result shows its first and last address and size (10.0.0.0 to 10.0.3.255, 1,024 addresses). If the block was written with host bits set (192.168.1.77/24), the real network is shown. For the usable host range, broadcast address and mask, use the subnet calculator.

How This Tool Works

ItemDetail
Where it runsIn your browser; nothing is sent to our server.
InputRanges (start - end, or "to"), CIDR blocks and single addresses, IPv4 and IPv6, up to 5,000 lines. Invalid lines are listed with the reason.
MethodRanges are sorted and merged, then each is split greedily into the largest aligned blocks, which gives the minimal list.
Shareable link?q= followed by a range or block opens the page with it converted.
StoredNothing.
Last verified10 November 2026

Frequently Asked Questions

How do I convert an IP range to CIDR?
Enter the first and last IP, such as 10.0.0.5 - 10.0.0.20: you get the smallest set of CIDR blocks that covers exactly that range, here five blocks from 10.0.0.5/32 to 10.0.0.20/32.
Why does one range need several CIDR blocks?
A CIDR block must have a power-of-two size (1, 2, 4, 8 … addresses) and start on a multiple of that size. Most ranges don't line up, so they are split into several aligned blocks.
How do I convert CIDR to an IP range?
Enter the block, such as 10.0.0.0/22: the range runs from the network address to the last address, 10.0.0.0 to 10.0.3.255 (1,024 addresses). The subnet calculator gives the usable host range too.
Can I merge many ranges at once?
Yes: paste one range, CIDR block or IP per line. Overlapping and touching ranges are merged first, then turned into the fewest blocks.

Next steps

Related Tools

Subnet Calculator
Network, broadcast, mask and host range of any IPv4 subnet.
IP CIDR Checker
Check a list of IPs against CIDR blocks.
IP Sorter
Sort and dedupe a list of IPv4 and IPv6 addresses.