ELI5: Explain Like I'm 5

Natural sort order

Okay, picture all the words you know printed out on pieces of paper. Now, think about how we put those words in order – usually we think about the first letter of each word and then look at the second letter and so on until we reach the end of the word. That's called sorting in alphabetical order.

But have you ever noticed that sometimes when you sort things alphabetically, the order seems a little bit weird? Like, if you have a list of file names on a computer, they might be sorted like this:

1. File-1.txt
2. File-10.txt
3. File-11.txt
4. File-2.txt
5. File-3.txt

That doesn't seem quite right, does it? If we sorted them using alphabetical order, it would look like this:

1. File-1.txt
2. File-10.txt
3. File-11.txt
4. File-2.txt
5. File-3.txt

That's because the computer is sorting them by looking at each letter one by one, but it's not taking into account the fact that numbers have a different meaning than letters. So, for example, if we think of the numbers as words, we'd sort them like this:

1. File-1.txt
2. File-2.txt
3. File-3.txt
4. File-10.txt
5. File-11.txt

That's called sorting in natural sort order, because we're taking into account the actual meaning of the words – whether they're letters or numbers – instead of just looking at them as a series of characters. It's like turning the words into toys and then sorting them according to how they're played with – the dolls go with the dolls, the blocks go with the blocks, and so on.