TBH I think all of these digressions into things like byte ordering and etc. are muddying the waters somewhat. Here's the most important, most basic point everyone should understand about sorting in computers:
By default (meaning, unless a more advanced algorithm is applied that does more complex interpretation of the inputs), a computer will sort string data (like filenames) by comparing them character-by-character, starting from the first. (Which is probably the leftmost, although not necessarily because RTL languages exist.)
That's correct for sorting of text strings, even if they're different lengths. Most of us would expect a list of names to be sorted like this, for example:
- Aaron
- Alexander
- Anna
- Annabelle
- Brian
The most significant letter in a string, when it comes to sorting, is the first one, and length is irrelevant except that strings with shorter total length come before longer ones that contain the same initial text.
Problem is, that's exactly wrong for numbers, which are supposed to be compared with their last digits aligned. When we're talking about numbers, length is the most critical factor: longer values are ALWAYS greater than shorter ones, because they have more significant digits. (Assume we're talking about integers here; decimal points complicate things further.) The fact that length is more significant than value is why we typically right-align lists of numbers.
Alphabetical sorting can sometimes produce the same results as numeric sorting, but only when the numbers are represented as strings of equal length. That's why padding with 0s fixed your issue. The sorting still isn't doing proper numeric comparison, though. (It's comparing the numbers as strings, character-by-character from left to right. But it turns out that comparing digit-by-digit, from left to right, is exactly how you would compare two n-digit numbers. The most significant digit is on the left, and the least significant is on the right.)
The sorting issue is also why so many in the computing industry (including myself) are big proponents of the ISO-8601 standard for representing dates as YYYY-MM-DD. As with numbers, dates in that form will happen to be correctly sorted by "dumb" alphabetical sorting, because the components are ordered left-to-right from most to least significant, which is exactly how alphabetical sorting works. The sorting isn't interpreting the string YYYY-MM-DD as a date, nor is it interpreting it as a number... but that's OK because it'll still sort correctly anyway.