IP Range to CIDR Converter Widget

Firewalls, cloud security groups and route tables want CIDR prefixes, but address ranges often arrive as 'from' and 'to'. This converter returns the shortest exact list of blocks, with netmasks and sizes, ready to copy one per line. It is the inverse of the subnet calculator, which expands one CIDR into its range.

Networking & IT Converter Runs in your browser Free · no ads

Customize your widget

Theme
Auto follows the visitor's light/dark setting.
Style
Attribution on your page
Optional and entirely your choice. The exact line is shown in the code below; it links to the tool with rel="nofollow".
More options
Starting values
Leave blank to use the widget's defaults. Visitors can still change every value.

Live preview

Exactly what your visitors will see

Embed code

<iframe src="https://a2z.tools/embed/w/ip-range-to-cidr" title="IP Range to CIDR Converter by A2Z Tools" width="100%" height="820" style="border:0;width:100%" loading="lazy" allow="clipboard-write"></iframe>

A plain iframe. Works everywhere, including site builders that strip scripts. Adjust height if your content needs more room.

Works with

How it works

A CIDR block is a run of 2^k addresses that starts on a multiple of its own size (RFC 4632 describes prefixes as power-of-two-sized, aligned blocks). An arbitrary range rarely fits one block, so the converter walks it greedily: from the current start address it takes the largest block that is both aligned at that address and ends on or before the last address, records it, and moves to the next address. This classic algorithm yields the minimal list. For 10.0.0.1 to 10.0.0.10 that is five blocks - .1/32, .2/31, .4/30, .8/31 and .10/32 - covering ten addresses; 192.168.1.0 to 192.168.1.255 collapses to the single 192.168.1.0/24. The worst case, 0.0.0.1 to 255.255.255.254, needs 62 blocks. Addresses must be four decimal octets from 0 to 255 without leading zeros (which some software reads as octal), and the start may not come after the end; the Swap button fixes that in one click.

Method

  • Address as a number = a x 16,777,216 + b x 65,536 + c x 256 + d
  • While start <= end: size = largest power of two with start mod size = 0 and start + size - 1 <= end
  • Emit start/(32 - log2 size); start = start + size
  • Netmask for /n = 2^32 - 2^(32 - n), written as four octets

Worked examples

Ragged range

Inputs: 10.0.0.1 to 10.0.0.10

Result: 5 blocks: 10.0.0.1/32, 10.0.0.2/31, 10.0.0.4/30, 10.0.0.8/31, 10.0.0.10/32; 10 addresses

Largest block is the /30 covering .4-.7.

Aligned range

Inputs: 192.168.1.0 to 192.168.1.255

Result: 1 block: 192.168.1.0/24; 256 addresses

The range starts on a multiple of 256 and spans exactly 256 addresses.

Limitations

  • IPv4 only; IPv6 ranges are not supported.
  • Accepts one contiguous range at a time; merging several ranges into a summary is not done.

Where publishers use it

  • A firewall vendor's documentation on importing provider IP ranges
  • A cloud-hosting knowledge base article about security-group rules
  • A network-engineering course exercise on CIDR aggregation
  • An ISP's support page listing customer address blocks
  • A bot-management or CDN guide on allow-listing a partner's published range

Questions

Why can't every range be written as one CIDR?

A CIDR block must contain a power-of-two number of addresses and start on a multiple of that size. 10.0.0.1-10.0.0.10 has ten addresses and starts on an odd address, so it needs five blocks (/32, /31, /30, /31, /32).

Is the list really the shortest possible?

Yes. Taking the largest aligned block at each step is the standard minimal decomposition for a contiguous range; no other set of non-overlapping CIDR blocks covers exactly the same addresses with fewer entries.

How is this different from the subnet calculator?

The subnet calculator starts from one CIDR, such as 192.168.1.0/24, and shows its network, broadcast and host range. This tool goes the other way: from a start and end address to the CIDR blocks that describe them.

Why are leading zeros refused?

Some tools read 010.0.0.1 as octal, where 010 means 8, while others read it as decimal 10. Rather than guess, the converter asks for plain decimal octets.

Does it support IPv6?

No, IPv4 only. IPv6 ranges follow the same greedy idea but use 128-bit addresses, which would need big-integer arithmetic in the widget.

Does it include network and broadcast addresses?

It covers every address from start to end inclusive. Whether the first and last addresses of each block are usable hosts depends on how the block is used; in a firewall rule every address counts.

Sources

  1. RFC 4632 - Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan - IETF . Prefix notation (address/length 0-32) and power-of-two sized, aligned address blocks. Checked 2026-10-01.

Cite or recommend this tool

If you reference this tool in an article, course or documentation, these formats are ready to copy. They are optional - nothing is added to your site unless you paste it.

A2Z Tools IP Range to CIDR Converter
https://a2z.tools/embed/ip-range-to-cidr
  • Subnet Calculator

    Developer Tools Calculator

    Network, broadcast, host range, masks and host count for any IPv4 CIDR, with subnet splitting.

    Get code
  • My IP Address

    Website & Security Tool

    Shows the visitor's public IPv4 or IPv6 address as A2Z sees it, with a copy button.

    Get code
  • Number Base Converter

    Education & Math Converter

    Binary, octal, decimal, hex and any base from 2 to 36 - exact for very large integers.

    Get code
  • Download Time Calculator

    Networking & IT Calculator New

    How long a file takes at a given connection speed - or the speed a deadline needs.

    Get code
  • Data Storage Converter

    Networking & IT Converter New

    Bits, bytes, kB to PB and KiB to PiB in one table - and why a 1 TB drive shows 931 GiB.

    Get code
  • Data Rate Converter

    Networking & IT Converter New

    Convert Mbps, Gbps and kbps to MB/s, MiB/s and back, with every rate unit side by side.

    Get code

Preview