A little help goes a long way. Find a tool/

Text FIELD NOTES · 4 MIN READ

Sorting Words: Alphabet, Length, and the Case Question

What a word sort really decides: what counts as a word, alphabetical vs length order, how ties break, and when case-sensitivity changes the result.

"Sort these words" sounds like one instruction, but it is really three decisions wearing a trench coat: what counts as a word, what key to sort on, and whether capital letters participate. Get all three wrong and the output looks random; get them right and a jumble like Banana apple Cherry fig snaps into a deterministic order you can defend line by line. The interesting part is that each decision has a default — and knowing the default is most of the skill.

What counts as a word

First, the text is split on whitespace — any run of spaces, tabs, or line breaks — and empty pieces are discarded. So one  two  three (with double spaces) yields exactly three words, and leading or trailing whitespace around the whole input disappears without a trace. This word-level splitting is what separates a word sorter from a line sorter: within a single string, every token is a citizen. If your data is structured as one item per line — a list of names, a column of values — you want the Line Sorter instead, because a word sort would scramble the words inside each line.

Alphabetical order and the case problem

Sort Banana apple Cherry fig alphabetically with case off — the default — and every word is compared by its lowercase form, so the answer is the dictionary order you expect:

input: Banana apple Cherry fig
alpha, asc, case off:   apple Banana Cherry fig

Switch case-sensitivity on and the same words come back as Banana Cherry apple fig. Nothing was mis-sorted: in case-sensitive comparison, words starting with uppercase letters compare as smaller than words starting with lowercase ones, because that is how the underlying character comparison works. Both orders are "correct" — they answer different questions. Case-insensitive asks "what order would a dictionary print these in?"; case-sensitive asks "what order does raw comparison produce?", which matters when casing itself carries meaning, such as in code identifiers or data where Apple the company must not equal apple the fruit.

Sorting by length — and the tie problem

The second key is word length. Sorting the same four words by length, ascending, gives fig apple Banana Cherry — the three-letter word first, the six-letter words last. But length alone is ambiguous: Banana and Cherry both have six letters, so a length-only comparison would leave their relative order at the mercy of the sort algorithm. That is why length sorts use an alphabetical tiebreak: equal-length words are ordered alphabetically, always, so the output is deterministic. Run the same input twice and you get the same answer, which is exactly what you want when the result feeds into something else.

length, asc:   fig apple Banana Cherry   (ties: Banana before Cherry)
length, desc:  Cherry Banana apple fig   (ties reverse too)

Descending flips the primary comparison — longest words first — and the alphabetical tiebreak flips with it, so the six-letter pair still sits together in a stable, predictable order.

Why sort words at all?

Three everyday jobs use word-level sorting. Vocabulary and keyword work: pulling the distinct terms of a text into alphabetical order before counting them, a task the Word Counter complements with its counts. Longest-word hunts: sort by length descending and the answer is the first word. And anagram-style puzzles: two texts are anagrams precisely when their sorted word (or letter) sequences match, so a sort is the cheapest test. For the bigger picture of how these word operations fit together — including sorting and joining as pipeline stages — see Find & Replace, Line Sorting, and Joining Text.

Reading the output honestly

The tool rejoins the sorted words with single spaces, which means multi-space input does not survive: whitespace runs collapse to one space in the result. That is almost always what you want for prose, but if exact spacing matters — code, poetry, aligned columns — a word sort is the wrong instrument; a line-based tool preserves it. Also worth remembering: the sort never changes the words themselves. Case is only used for comparison; Cherry comes out spelled exactly as it went in, wherever it lands.

Try it yourself

Paste Banana apple Cherry fig into the Sort Words tool and run it all four ways — alphabetical and by length, each ascending and descending — to see the tiebreak behavior with your own eyes. Then toggle case-sensitivity and watch the alphabetical order flip to raw-comparison order. Finally, paste the same words as separate lines into the Line Sorter and notice how the sort unit changes the question being answered.

Frequently asked questions

How is Sort Words different from the Line Sorter?
The Line Sorter reorders whole lines of a text block. Sort Words splits a single string on whitespace and reorders the words inside it — the sort unit is a word, not a line. For one-item-per-line data, the Line Sorter is the right tool.
How are ties broken when sorting by length?
Equal-length words fall back to an alphabetical comparison, so the result is deterministic: Banana and Cherry both have six letters and always come out Banana before Cherry in ascending order. Running the same input twice always gives the same output.
Is the alphabetical sort case-sensitive?
By default no — words compare by their lowercase forms, so apple sorts before Banana. With case-sensitive mode on, raw character comparison applies, where uppercase letters sort before lowercase ones, so Banana and Cherry come before apple.
What happens to extra whitespace?
Input is split on any run of spaces, tabs, or line breaks, and empty pieces are dropped, so double spaces and stray whitespace never create phantom words. The result is rejoined with single spaces.
Does sorting change the words themselves?
No. Case and punctuation are used only for comparison; every word comes out spelled exactly as it went in, wherever it lands in the order.