You sort a list of file names or invoice lines and get Invoice 1, Invoice 10, Invoice 11, Invoice 2, Invoice 3. You alphabetise a list of team members and all the names starting with a lowercase letter end up at the bottom. Or you want to randomise the order of presenters for a meeting and need a method that is actually fair.
Sorting looks trivial until the result is wrong. This guide explains the different kinds of sort order, why computers make those surprising choices, and how to get the order you meant, in a browser, a spreadsheet or on the command line.
How computers compare text
The simplest way to sort text is to compare it character by character using each character's code number. In that scheme:
- digits come before uppercase letters, which come before lowercase letters;
1is compared with2before anything else, so10sorts before2because its first character,1, is smaller.
That is why a plain sort gives Item 1, Item 10, Item 2. The computer is not wrong; it is sorting characters, not numbers.
Alphabetical order for people
Human-friendly alphabetical sorting uses collation: language-aware rules that ignore case differences, place accented letters next to their base letters (so é sits near e) and handle other language details. Modern operating systems and browsers include these rules.
Natural (numeric) order
Natural sorting treats runs of digits as numbers. Item 2 comes before Item 10 because 2 is less than 10. This is how file managers on Windows and macOS usually order file names, and it is what most people expect for anything numbered: chapters, invoice numbers, versions, room numbers.
Other useful orders
| Order | Example use |
|---|---|
| Z to A | Newest-first lists where names start with dates in YYYY-MM-DD format |
| Shortest first | Finding very short keywords or tags that may be typos |
| Longest first | Spotting overlong titles or product names |
| Reverse current order | Flipping a list that was pasted upside down |
| Random shuffle | Draw order, presentation order, randomised test items |
Sort lines in your browser
Our Sort Lines tool offers all of these orders and updates the result instantly.
- Open Sort Lines.
- Paste your list into Lines to sort, one item per line. Click Sample to see a mixed list with numbers and capitals.
- Choose a Sort order:
- Alphabetical A → Z or Alphabetical Z → A
- Natural / numeric (1, 2, 10) or Natural / numeric, descending
- Length: shortest first or Length: longest first
- Random shuffle (with a Shuffle again button)
- Reverse current order
- Adjust the switches: Ignore case (on by default), Remove duplicates and Remove empty lines (on by default).
- Copy the result from the Sorted panel, which shows the line count, or download it as a .txt file.
Alphabetical and natural sorting use your browser's language-aware comparison, so accented letters are placed sensibly. The random shuffle gives every possible order the same chance, so it is suitable for everyday draws such as deciding who presents first.
Other ways to sort a list
Excel and Google Sheets
Select the column and use Data → Sort (Excel: Sort A to Z; Google Sheets: Sort range). In Excel 365 and Google Sheets, =SORT(A2:A100) returns a sorted copy.
Spreadsheets sort real numbers numerically, but numbers embedded in text, like "Item 10", are sorted as text, so they fall into the same 1, 10, 2 trap. A common workaround is a helper column that extracts the number, then sorting by that column. Spreadsheets are the better choice when each line has several columns that must stay together.
Command line
On macOS and Linux:
sort list.txt # alphabetical
sort -f list.txt # ignore case
sort -V list.txt # version / natural order (GNU sort)
sort -n list.txt # numeric, when lines start with numbers
sort -R list.txt # random order (GNU sort)
The command line is ideal for huge files and scripts. Exact options differ between systems, so check man sort on yours.
Word processors
Microsoft Word can sort paragraphs via Home → Sort (the A–Z button). Google Docs does not sort lines natively, although add-ons can.
Pitfalls and fixes
Numbers without leading zeros
If you control the naming, pad numbers with leading zeros: Item 01, Item 02 … Item 10. Then even a basic alphabetical sort works everywhere, including on systems you do not control.
Dates in the wrong format
Dates like 03/04/2026 do not sort chronologically as text, and they are ambiguous between countries. Use the ISO format 2026-04-03 in file names and lists; it sorts correctly with a plain alphabetical sort.
Leading spaces and invisible characters
A line that starts with a space sorts before lines starting with letters. If one item appears in the wrong place, check for leading spaces or tabs and clean the list with Remove Extra Spaces.
Duplicates that survive
The Remove duplicates switch follows the Ignore case setting. With Ignore case on, Apple and apple are treated as one item. For more control, such as keeping the last occurrence, use Remove Duplicate Lines before sorting.
Names with prefixes
"van Dijk", "de la Cruz" and "O'Brien" sort differently depending on convention. Collation cannot know whether your directory files "van Dijk" under V or D, so decide on a rule and adjust those lines manually.
When sorting is not the right tool
- Picking a winner: if you need to draw one or more random names, the List Randomizer is built for draws and can pick N items directly.
- Reversing text rather than lines: to flip characters or words inside a line, use Reverse Text.
- Counting repeated items: to see how often each word appears, use the Word Frequency Counter.
Frequently asked questions
Why does 10 come before 2 when I sort?
A plain text sort compares character by character, and "1" is smaller than "2", so "10" comes first. Natural sorting reads the digits as numbers and puts 2 before 10.
How do I sort a list alphabetically and ignore capital letters?
Choose Alphabetical A → Z and keep Ignore case switched on. Uppercase and lowercase versions of a word then sort together.
Is the random shuffle really random?
It uses a standard unbiased shuffle algorithm with the browser's random number generator, so every order is equally likely. For formal prize draws, use a method your rules specify and keep a record.
Can I sort a list by line length?
Yes. Choose Length: shortest first or Length: longest first. Lines of equal length are then ordered alphabetically.
Does sorting remove blank lines?
By default, yes: Remove empty lines is switched on. Turn it off if blank lines are meaningful in your list.