Text & writing
How Alphabetical Sorting Works
Alphabetical order feels obvious until a computer sorts “Zebra” before “apple”, or puts “éclair” after “zebra”. Sorting text correctly depends on how characters are compared — by their code numbers or by language rules. This guide explains the difference and what affects the result.
Ready to try the tool this guide describes?
Code-point order
The simplest way to sort is by each character’s numeric code. In ASCII and Unicode, the capital letters A–Z (65–90) come before the lowercase letters a–z (97–122). Sorting this way puts every capitalized word before every lowercase word, so “Zebra” sorts before “apple”, and accented letters, which have higher codes, sort after “z”.
Language-aware collation
Collation compares text the way people expect for a particular language. The Unicode Collation Algorithm treats letters first, then accents, then case, so “apple” and “Apple” sort together and “é” sorts next to “e”. Browsers and programming languages expose this — JavaScript’s Intl.Collator, for example.
Language changes the order
Alphabetical order is not universal. In Swedish, å, ä, and ö are separate letters that come after z, while in German ä is usually sorted with a. The same list can therefore sort differently depending on the language rules used.
Other details that affect sorting
- Punctuation and digits usually sort before letters.
- Numbers are compared digit by digit unless the sort is number-aware, so “10” comes before “2”.
- A stable sort keeps lines that compare as equal in their original order.
How Alphabetical Sorting Works FAQ
- Why do capital letters sort before lowercase letters?
- When sorting by character code, A–Z (65–90) come before a–z (97–122). Language-aware sorting groups them together instead.
- What is collation?
- The set of rules a language uses to put text in order, covering letters, accents, and case.
- Why did an accented word sort after “z”?
- The sort compared character codes, and accented letters have higher codes than unaccented ones. Collation-based sorting places them next to their base letters.
- Is alphabetical order the same in every language?
- No. Swedish, for example, sorts å, ä, and ö after z, while German usually sorts ä with a.
- What is a stable sort?
- One that keeps items that compare as equal in their original order.
Related guides
- Natural Sort OrderWhy alphabetical sorting puts “10” before “2”, how natural number-aware sorting works, and the zero-padding workaround for tools that sort as text.
- Alphabetizing Names and TitlesHow to sort people by surname, file titles without “The”, and choose between word-by-word and letter-by-letter order before sorting a list.
Open the tool
Jump into Sort Lines Alphabetically when you are ready to process your files.
