Article

How Alphabetical Sorting Actually Works (It's Not Quite A-to-Z)

Published 2026-09-14

Why "Zebra" can sort before "apple"

If you've ever sorted a list "alphabetically" and ended up with all the capitalized words bunched together before the lowercase ones, you've run into how computers actually sort text by default. Under the hood, most software doesn't compare letters the way a dictionary does — it compares each character's underlying numeric code (from a standard called Unicode, and before it, ASCII), and in that scheme, every uppercase letter has a lower number than every lowercase letter. That's why a strict, case-sensitive sort puts "Zebra" before "apple": capital Z (numeric code 90) comes before lowercase a (numeric code 97).

Where numbers and symbols land

In the same numeric scheme, digits (0-9) sit below both uppercase and lowercase letters, and common punctuation marks are scattered both above and below letters depending on the specific symbol. This is why a raw sort of file names or list items can put "10-report" before "2-report" (comparing character by character, "1" is less than "2") — a classic case of alphabetical sort not matching the numeric order a human expects.

The fix: case-insensitive sorting

Most of the time, what people actually want is a case-insensitive sort, where "apple," "Apple" and "APPLE" are treated identically for ordering purposes, only falling back to case as a tiebreaker (or not at all). This matches how a dictionary or a phone book orders entries, and it's what most spreadsheet software defaults to as well.

When you'd want strict sorting instead

Case-sensitive sorting still has real uses: programmers sorting variable names, or anyone who specifically needs to group all-caps entries (like acronyms or headers) separately from regular text. It's worth knowing both behaviors exist so an unexpected sort order doesn't feel like a bug.

Try it yourself

Our Text Sorter defaults to case-insensitive sorting (the behavior most people expect) but lets you switch it off, sort ascending or descending, and remove duplicate lines at the same time — useful for cleaning up a list of names, tags, or file names before using it elsewhere.

Ready to try it yourself?
Open the Text Sorter →