Why Does 10 Come Before 2 When Sorting? Alphabetical vs Numeric
Why sorting a list puts 10 before 2, how alphabetical and numeric sorting differ, and how to sort numbered lists, prices and mixed lines in the right order.
The short answer
10 comes before 2 because an alphabetical sort compares text one character at a time, and the character "1" comes before "2". It never looks at the number as a whole. To sort numbers by value, use a numeric sort instead. In the Sort Text Lines tool, choose Numeric rather than A → Z, and 1, 2, 10, 25, 100 will come out in the order you expect.
What alphabetical sorting actually does
An alphabetical (or "lexicographic") sort compares two lines from the first character. If the first characters differ, that decides the order. Only when they match does it move to the second character, and so on.
Compare "10" and "2":
- First character: "1" versus "2".
- "1" comes first, so "10" is placed before "2". The second character is never checked.
The same rule explains why "100" comes before "25", and why "item 10" lands between "item 1" and "item 2".
Here is the same list sorted both ways in the tool:
| Input order | A → Z result | Numeric result |
|---|---|---|
| 10 | 1 | 1 |
| 2 | 10 | 2 |
| 1 | 100 | 10 |
| 100 | 2 | 25 |
| 25 | 25 | 100 |
How the Numeric mode works
The Numeric option reads the number at the start of each line and sorts by its value. That works well for:
- Plain numbers, one per line.
- Lines that begin with a number, such as "2 pears" or "10 apples".
- Decimals and negative numbers, such as 3.5 or -12.
For example, these lines:
come out as "1 fig", "2 pears", "10 apples".
Where Numeric mode cannot help
Because it reads only a leading number, Numeric mode is not designed for:
- Numbers in the middle or at the end of a line, such as "item 10" or "Invoice 2026-10". The line does not start with a digit, so no number is found.
- Currency symbols in front, such as "₹500" or "$20". The symbol comes first, so the line is not read as a number. Remove the symbol, sort, then add it back with the Find and Replace tool if needed.
- Thousands separators, such as "1,250". Reading stops at the comma, so 1,250 is treated as 1. Remove commas before sorting.
Lines without a leading number end up in an unpredictable position, so keep a numeric list numeric.
How to sort a list in the right order
Fixing "item 1, item 10, item 2"
Labels with numbers at the end are the hardest case, because neither alphabetical nor leading-number sorting handles them. Two practical fixes:
Fix 1: Pad the numbers with zeros
If every number has the same number of digits, alphabetical sorting gives the right order. "item 01", "item 02", "item 10" sort correctly because "0" comes before "1". This is why file names such as "photo_001.jpg" are common. Make all numbers the same width as the largest one: up to 99 needs two digits, up to 999 needs three.
Fix 2: Move the number to the front
Rewrite "item 10" as "10 item", sort with Numeric, then rewrite back. With a regular expression in the Find and Replace tool, the pattern (\w+) (\d+) and replacement $2 $1 swaps the two parts of each line. The guide to find and replace with regex explains how capture groups like $1 work.
Capital letters and accents
The A → Z mode uses your browser's language-aware comparison, not raw character codes. In practice that means:
- Upper and lower case sort together. "apple" and "Banana" come out as apple, Banana, not with all capitals first.
- When only case differs, lower case is placed first: "a" before "A".
- Accented letters sort near their plain letter, so "é" sits with "e" rather than after "z".
This is usually what people expect when sorting names or keywords. If you need strict upper-case-first order (as some programming tools do), convert everything to one case first.
Removing duplicates while sorting
The Remove duplicates option keeps the first copy of each line and drops exact repeats. "Exact" matters:
- "apple" and "Apple" are treated as different lines.
- "apple" and "apple " (with a trailing space) are also different.
If your list comes from a spreadsheet or a copy-paste, there may be hidden spaces. For more control, such as ignoring case or trimming spaces, use the dedicated tool covered in how to remove duplicate lines from a list.
Other sort modes and when to use them
- Z → A: reverse alphabetical, useful for newest-first lists when lines start with dates written as YYYY-MM-DD.
- Shortest first / Longest first: handy for spotting very long keywords or titles, or for finding empty and one-word lines.
- Random shuffle: good for casually mixing a list, such as quiz questions. It is not designed as a fair draw, so for raffles or prize winners use a method built for that, as explained in picking random numbers without repeats.
Dates: sort them as text the right way
Dates sort correctly as plain text only in year-month-day order with leading zeros: 2026-01-05, 2026-10-17. Formats like 17/10/2026 or 5 Jan 2026 sort by the day first and give a jumbled order. Convert dates to YYYY-MM-DD before sorting alphabetically.
Frequently asked questions
Why does 10 come before 2 when I sort?
An alphabetical sort compares text character by character. The first character of 10 is 1, which comes before 2, so 10 is placed first. Use a numeric sort to order by value.
How do I sort numbers in the correct order?
Put one number per line and use the Numeric mode in Sort Text Lines. It reads the number at the start of each line and sorts by its value: 1, 2, 10, 25, 100.
How do I sort item 1, item 2, item 10 correctly?
Pad the numbers with zeros (item 01, item 02, item 10) and sort A to Z, or move the number to the start of each line and use the Numeric sort.
Does the alphabetical sort put capital letters first?
No. It uses language-aware comparison, so apple and Banana sort together as apple, Banana. When two lines differ only in case, the lower-case one comes first.
Put this guide into practice with our free online tool — no signup required.
Open tool