IP Address Sorter

Sort IPv4 and IPv6 addresses by value, remove duplicates, group by subnet or collapse to CIDR blocks.
Output
Options
Result

8 different addresses sorted · 1 duplicate removed

How to Sort IP Addresses Correctly

IP addresses must be sorted as numbers, not text: as text, 10.0.0.10 comes before 10.0.0.2. Paste a list (or any text) to sort IPv4 and IPv6 addresses numerically, remove duplicates and group them by subnet.

Compare each octet as a number, left to right; for IPv6 compare the full 128-bit value. That's what this page does: it reads each address, whatever its written form, sorts by value with IPv4 before IPv6, and writes IPv6 in its standard short form. Lines without a valid address are listed with the reason, so nothing disappears silently.

Why Excel and Google Sheets Sort IP Addresses Wrongly

Spreadsheets sort IPs as text; split the octets into columns or pad them with zeros first.

As text, "10.0.0.10" comes before "10.0.0.2" because the character "1" is smaller than "2". Add a helper column next to the addresses (in column A), fill it down, and sort the sheet by it:

SpreadsheetHelper column formula
Excel 365=TEXTJOIN(".",TRUE,TEXT(TEXTSPLIT(A2,"."),"000")) turns 10.0.0.2 into 010.000.000.002, which sorts correctly as text.
Google Sheets=JOIN(".",ARRAYFORMULA(TEXT(SPLIT(A2,"."),"000"))), same result.
Any Excel version=SUMPRODUCT(--MID(SUBSTITUTE(A2,".",REPT(" ",100)),{1,101,201,301},100),{16777216,65536,256,1}) turns the address into one number (10.0.0.2 becomes 167772162).

For IPv6, spreadsheets can't hold 128-bit numbers. Expand the addresses first with our IPv6 expander: fully expanded addresses, with every group written as four lower-case digits, do sort correctly as text.

Group and Collapse

Group sorted addresses by /24 (or /64) and collapse consecutive ones into CIDR blocks.

  • Grouped by subnet puts a header line before each /24, /16 or /8 (IPv4) and /64 to /32 (IPv6) network, with its count: handy for firewall reviews and abuse reports.
  • Collapsed to CIDR blocks merges runs of consecutive addresses into the fewest blocks: 256 addresses from 192.0.2.0 to 192.0.2.255 become 192.0.2.0/24. Use it to shorten allow-lists and block-lists. For a single start-to-end range, use the range to CIDR converter.

How This Tool Works

ItemDetail
Where it runsIn your browser; nothing is sent to our server.
InputOne address per line, or any text: every valid IPv4 and IPv6 address in it is found, including addresses with ports or in brackets.
OrderNumeric: IPv4 by its 32-bit value, then IPv6 by its 128-bit value. Duplicates are compared by value, so different spellings of one IPv6 address count as one.
StoredNothing.
Last verified10 November 2026

Frequently Asked Questions

How do I sort IP addresses correctly?
Paste them above: they're sorted by numeric value, so 10.0.0.2 comes before 10.0.0.10, and IPv6 addresses are sorted by their full 128-bit value.
Why does Excel sort IP addresses wrongly?
It treats them as text and compares character by character. Add a helper column that pads each number to three digits, or turns the address into one number, and sort by that column.
Can I sort IPv6 addresses?
Yes, by their full 128-bit value, whatever their written form: 2001:db8::a and 2001:0db8:0:0:0:0:0:000a are the same address and sort together.

Next steps

Related Tools

IP Extractor
Pull every IP address out of logs or any text.
IP Address Validator
Is it a valid IPv4 or IPv6 address? Many at once.
IP Range to CIDR Converter
Turn any IP range into CIDR blocks, IPv4 and IPv6.
IPv6 Expander
Write any IPv6 address out in full.