Skip to content
Utilboxes

How to sort a list properly — and why item10 comes before item2

Sort lines alphabetically, numerically or by length, fix the item10-before-item2 problem with natural sorting, handle accents, and shuffle a list fairly.

Published

Tools for this job: Sort Lines · Remove Duplicate Lines · Random Number Generator

Sorting looks like the simplest thing a computer does, until a list of files comes out as file1, file10, file11, file2. The computer is not wrong — it is sorting a different way from the one you meant.

Sort a list step by step

  1. Paste the lines into Sort Lines.
  2. Choose a method: alphabetical, numeric, by length, or random.
  3. Choose the direction — A to Z or Z to A, smallest or largest first.
  4. Turn on natural sorting if the lines contain numbers, then copy the result.

The text is sorted in your browser and never sent anywhere.

Why item10 comes before item2

A plain alphabetical sort compares text character by character. “item10” and “item2” match up to “item”, then compare “1” with “2”. Since 1 comes before 2, item10 wins — the computer never looks at the number as a whole.

Natural sorting reads runs of digits as numbers, so the order becomes item2, item10, item100 — the order a person would use. Turn it on for file names, version numbers, chapter titles, house numbers and anything else that mixes words and numbers.

Numeric sorting

For a list of plain numbers, numeric mode sorts by value: 9 before 10 before 100. Alphabetical mode would give 10, 100, 9. If a list contains currency symbols or units, the numbers may not be recognised; strip them first, or use natural sorting.

Accents and other languages

Alphabetical sorting here uses your browser's language-aware comparison, so “é” sorts next to “e” rather than after “z”, as a plain byte comparison would put it. Names such as Émile and Eva end up where a reader expects them.

Sorting dates

Dates written as text sort badly. 01/03/2026, 15/02/2026 and 28/12/2025 sort by day first, which mixes up months and years. The fix is to write dates in year-month-day order, as in the ISO 8601 format: 2025-12-28, 2026-02-15, 2026-03-01. Dates in that form sort correctly with a plain alphabetical sort, which is why it is used for file names, logs and spreadsheets that will be sorted.

Sorting by length

Ordering lines from shortest to longest is handy for spotting outliers — a product code that is too long, an empty or truncated entry — and for laying out lists of keywords or tags.

Shuffling fairly

The random option puts the lines in a random order using a method that gives every possible order an equal chance, driven by your browser's cryptographic random numbers. The common shortcut of sorting by a random key does not do that. Use it for seating plans, presentation orders or a fair running order. For picking winners by number, see the Random Number Generator.

Tidy first

  • Remove duplicates with Remove Duplicate Lines if the list may contain repeats.
  • Watch for leading spaces, which make a line sort before everything else.
  • Decide whether “The Beatles” should sort under T or B; computers sort under T.

Tools used in this guide

More tools for this job

All guides