Skip to content
ToolPlankDEV
Developer Tools
100% In-Browser Execution

Updated:

IP Range to CIDR Converter

Paste start and end addresses, one range per line, and get the exact ip range to cidr blocks that cover them. Aggregate a whole list into fewer blocks, exclude subnets, and copy the result as nginx, Apache or iptables rules. Nothing is uploaded.

Options:

Only nginx, Apache and iptables output use a rule type

IP ranges

Input
0 chars · 0 lines

CIDR blocks

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Summary and notes

Counts, reversed ranges that were swapped and lines that need fixing appear here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use IP Range to CIDR

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your IP ranges

    Type or paste one range per line, or open a .txt, .csv or .tsv file. Start and end can be separated by a dash, the word to, a comma or a tab, so a column copied from Excel works. 192.168.1.10-20 is read as 192.168.1.10 to 192.168.1.20. Example loads a mixed list, and the sample buttons load a vendor list, a labeled spreadsheet and a list that mixes ranges with blocks.

  2. 02

    Choose each range or aggregate

    Each range turns every line into its own blocks, in the order you gave. Aggregate joins ranges that overlap or touch first and writes the smallest set of blocks for the whole list, sorted with IPv4 first.

  3. 03

    Exclude subnets and pick a format

    Type blocks, single addresses or ranges into Exclude to cut them out of the result. Pick CIDR list, comma list, CSV, JSON, or ready-made nginx, Apache or iptables rules, and choose whether they allow or deny.

  4. 04

    Check the summary and copy

    The summary shows how many ranges came in, how many blocks came out, the addresses covered and any line that needs fixing. Press Copy, or Download to save the result as a file.

How to convert an IP range to CIDR

A CIDR block must start on an address that its size divides evenly and must contain a power of two addresses. Most ranges do not fit that shape. 10.0.0.10 to 10.0.0.20 is eleven addresses that begin in the middle of a block, so no single prefix describes it. The ip range to cidr conversion splits it into the fewest blocks that cover exactly those addresses and nothing else.

The tool works from the start of the range. At each step it takes the largest block that is aligned at the current address and still fits before the end, then moves on. The result is the minimal exact set, never an over-wide block that would include addresses you did not ask for.

Text
10.0.0.10 - 10.0.0.20

10.0.0.10/31
10.0.0.12/30
10.0.0.16/30
10.0.0.20/32

That is why one range becomes four blocks here. The conversion runs in your browser, as the Privacy Policy describes.

Input the way your data comes

Ranges rarely arrive in one clean format, so the reader accepts the common ones on the same list. Start and end can be joined by a hyphen, an en dash, an em dash, the word to, a comma, a semicolon, a tab or a space. A short form such as 192.168.1.10-20 repeats the first three numbers for you.

  • A line with a single address becomes a /32 or /128 block.
  • A line that is already a CIDR block passes through. A block with host bits set, such as 10.0.0.5/24, is rounded to 10.0.0.0/24.
  • A header line such as start,end is skipped, and extra columns after the end address, like a site name, are ignored and counted in the summary.
  • Text after a hash sign or two slashes is a comment.

Mixed IPv4 and IPv6 lists work. A single range cannot mix them, so a line such as 10.0.0.1 - ::1 is reported with its line number.

Aggregate ranges into fewer CIDR blocks

Vendor lists often hold ranges that overlap or sit next to each other. Setting Mode to Aggregate list joins them before converting, so the output is as short as it can be. This is CIDR aggregation, also called route summarization or supernetting when it is done to routes.

Text
34.64.0.0 - 34.64.255.255
34.65.0.0 - 34.65.255.255
34.66.0.0 - 34.66.127.255
34.66.64.0 - 34.66.255.255
35.190.0.0 - 35.190.63.255

34.64.0.0/15
34.66.0.0/16
35.190.0.0/18

Five ranges became three blocks. The first two ranges touch, so they form a /15. The next two overlap, so they form one /16. The summary reports how many ranges the aggregation joined. In Each range mode the same list would give one set of blocks per line, and a note suggests Aggregate when it sees overlaps.

Exclude a subnet from a range

To allow a whole network except one part, give the whole network as the input and put the part in Exclude. The tool subtracts it and writes the blocks that remain. Exclude accepts blocks, single addresses and ranges, separated by spaces or commas, and works in both modes.

Text
10.0.0.0/8  excluding  10.1.0.0/16

10.0.0.0/16
10.2.0.0/15
10.4.0.0/14
10.8.0.0/13
10.16.0.0/12
10.32.0.0/11
10.64.0.0/10
10.128.0.0/9

A hole in the middle of a large block costs several blocks, one for each side at every size. If everything in the list falls inside the excluded space, the tool says so instead of returning nothing.

Output for nginx, Apache and iptables

Output turns the blocks into text you can paste into a configuration. The templates are plain text, so nothing is fetched or checked against a server. Rule type chooses allow or deny. IPv6 blocks use ip6tables for iptables.

  • nginx writes allow or deny lines and ends with deny all or allow all, which is how nginx access rules are normally closed.
  • Apache writes Require ip lines inside RequireAny for allow, and Require not ip lines inside RequireAll with Require all granted for deny.
  • iptables writes one append rule per block with ACCEPT or DROP.
  • CSV adds the first and last address, the number of addresses and the source line. JSON gives an array of strings.
Text
allow 10.0.0.0/30;
allow 2001:db8::/126;
deny all;

Test any generated rule on a non-production server first. A wrong allow list can lock you out.

Reversed ranges and other mistakes

A range whose start is above its end is a common slip in spreadsheets. With Reversed ranges set to Swap, the two addresses are exchanged and the line is listed in the notes. Set it to Error to leave such lines out and list them instead. An octet above 255, a leading zero, a mix of IPv4 and IPv6 in one range, and a netmask with gaps are always reported with the line number.

To go the other way, from blocks to first and last addresses, use CIDR to IP Range. To tidy a list first, Sort Lines orders it, Compare Two Lists shows what changed between two versions, and List to Comma Separated joins a column into one line.

Limits

  • The tool does arithmetic only. It does not look up who owns a range or where it is.
  • Rules for nginx, Apache and iptables are templates for the common case. Check them against your own configuration.
  • IPv6 zone identifiers such as %eth0 are rejected.
  • A line with more than two addresses and no slash uses the first two as the range and ignores the rest.

Frequently Asked Questions

Technical Q&A for IP Range to CIDR

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the start and end address, for example 10.0.0.10 - 10.0.0.20, and read the blocks. The tool splits the range into the fewest CIDR blocks that cover exactly those addresses.

Because a CIDR block must start on a boundary that matches its size and hold a power of two addresses. A range that starts or ends off those boundaries needs several blocks.

Yes. Set Mode to Aggregate list and the tool joins overlapping and touching ranges before it converts them, so the output is the smallest set.

Enter the whole range or block as the input and type the part to remove into Exclude. The result holds the blocks that remain.

Yes. IPv6 ranges convert with exact 128-bit math, and IPv4 and IPv6 can be mixed in one list, though not inside one range.

It is a short form for 192.168.1.10 to 192.168.1.20. The tool repeats the first three numbers of the start address for you.

Yes. Copy two columns, start and end, and paste them. The tab between them is read as the separator, and a header row is skipped.

By default the two addresses are swapped and the line is noted in the summary. Set Reversed ranges to Error if you would rather see the line listed as a problem.

Choose nginx, Apache or iptables under Output and pick Allow or Deny. The tool writes one rule per block that you can paste into your configuration.

No. The conversion runs in your browser, so ranges from internal networks stay on your computer.