IP Address Sorter |
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:
| Spreadsheet | Helper 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
| Item | Detail |
|---|---|
| Where it runs | In your browser; nothing is sent to our server. |
| Input | One address per line, or any text: every valid IPv4 and IPv6 address in it is found, including addresses with ports or in brackets. |
| Order | Numeric: 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. |
| Stored | Nothing. |
| Last verified | 10 November 2026 |
Frequently Asked Questions
How do I sort IP addresses correctly?
Why does Excel sort IP addresses wrongly?
Can I sort IPv6 addresses?
Next steps