Natural Sort Online — Sort Filenames and Numbered Lists Correctly
Updated: May 2026
Standard alphabetical sort treats every character as a code point, which means numbers embedded in text are compared digit by digit. "file10" sorts before "file2" because "1" comes before "2". Natural sort fixes this by comparing number sequences as integers, giving results that match human expectations.
Free · No upload · In your browser
The problem with standard sort for numbered lists
Lexicographic order compares strings character by character using their numeric code points. For the digit characters 0–9, code points are 48–57. When comparing "file9" and "file10", the sort looks at the first differing character after "file": "9" (code point 57) versus "1" (code point 49). Since 57 is greater than 49, "file9" sorts after "file10" in ascending order — the opposite of what you want.
Standard A-Z sort ✗
file1.txt
file10.txt
file11.txt
file2.txt
file20.txt
file3.txt
file9.txt
Natural A-Z sort ✓
file1.txt
file2.txt
file3.txt
file9.txt
file10.txt
file11.txt
file20.txt
Use natural sort any time your lines contain numbers that represent quantity, sequence, or version. Use standard sort for identifiers where the number is purely part of a string with no numeric meaning.
How natural sort works
Natural sort splits each string into alternating runs of non-numeric and numeric characters. When comparing two strings, it aligns these segments and compares non-numeric segments lexicographically and numeric segments as integers. This means "v1.10.2" correctly sorts after "v1.9.0" because the second segment "10" is compared as the integer 10, which is greater than 9.
Modern implementations use the Intl.Collator API with the numeric: true option, which applies the same logic in a locale-aware way. Flowfiles uses localeCompare with { numeric: true }, the recommended approach for browser-based natural sort.
When to use natural sort
- Filenames — photo1.jpg through photo100.jpg, chapter1 through chapter20
- Software versions — v1.2, v1.10, v2.0; changelogs and release notes
- Issue or ticket numbers — BUG-1 through BUG-200
- Street addresses — 1 Main St, 10 Main St, 100 Main St
- Product SKUs — SKU-001 through SKU-999
- Log entries with sequence numbers — any log where lines are prefixed with a counter
Frequently asked questions
Why does file10 sort before file2 in a standard sort?
Standard (lexicographic) sort compares characters one by one. "file10" and "file2" share the prefix "file". The next characters are "1" and "2". Since "1" has a lower code point than "2", "file10" sorts before "file2". Natural sort treats "10" and "2" as integers and correctly places "file2" first.
Does natural sort work with version numbers like v1.10.2?
Yes. The numeric: true collation option treats each sequence of digits as an integer. "v1.9.0" sorts before "v1.10.0" because 9 < 10 when compared as integers, not as characters.
Can I combine natural sort with duplicate removal?
Yes. Enable "Remove duplicates" along with "Natural A → Z" sort mode. Duplicates are removed before sorting, and the remaining unique lines are sorted in natural ascending order.