You create files named photo-1, photo-2, and photo-10, then sort the folder by name. You expect 1, 2, 10. In some apps that is exactly what you get. In others, photo-10 may appear before photo-2.

Nothing is necessarily wrong with the files. The difference comes from what sorting by name means to the software doing the sorting. A program can compare filenames as text, or it can recognise runs of digits as numbers and compare their numerical values. Those two rules can produce different orders from the same names.

Understanding that distinction helps when organising photos, scanned pages, project exports, backups, or any other files whose names are meant to carry an order.

A filename is text first

A filename may contain digits, but the filename itself is still a name. The 10 in chapter-10.txt is not automatically stored as a separate chapter-number field that every program must understand.

When software sorts a list of files, it therefore needs a rule for comparing the names. A simple approach is to compare the text from left to right.

Consider these names:

  • page-1.pdf
  • page-2.pdf
  • page-10.pdf

The beginning, page-, is identical in all three. The first difference comes after that prefix. If the sorter is comparing the remaining characters as text, the first character of 10 is 1. That puts page-10.pdf near page-1.pdf, before the name beginning with 2.

A text-oriented result can therefore look like this:

page-1.pdfpage-10.pdfpage-2.pdf

That order can feel strange because a person reading the filenames is likely to interpret 1, 2, and 10 as numbers rather than as separate characters.

Natural sorting treats digit groups more like numbers

Many file managers and applications use a more human-friendly approach often called natural sorting or numeric-aware sorting. Instead of treating every digit independently, the software can recognise a run such as 10 as a number and compare its value with the other numeric parts of the names.

With that approach, the same three files can appear as:

page-1.pdfpage-2.pdfpage-10.pdf

This matches the order most people expect for numbered pages.

The important point is that natural sorting is a software behaviour, not a property stored inside the filenames. Two applications can display the same folder in different orders because they use different comparison rules. The operating system, file manager, archive utility, media application, website, or command-line tool involved can each make its own sorting choices.

That is why a folder that looks correctly ordered on your computer may look different after you upload the files somewhere else or open them in another program.

Leading zeros make text sorting more predictable

If the files need to keep the same visible order across software with different sorting rules, leading zeros are a useful naming technique.

Instead of this:

page-1.pdf, page-2.pdf, page-10.pdf

use this:

page-01.pdf, page-02.pdf, page-10.pdf

Now the numeric part has the same width. A left-to-right text comparison sees 01, 02, and 10, which already follows the intended numerical order.

If you expect hundreds of files, use enough digits for that range, for example:

scan-001.jpg, scan-002.jpg, scan-010.jpg, scan-100.jpg

This does not give the filename a special numerical type. It simply designs the text so that ordinary text ordering and numerical ordering agree for the sequence you care about.

Choose the width before creating a large set when possible. Renaming 1 through 99 to three-digit numbers later is possible, but starting with 001 is easier if you already know the collection may reach the hundreds.

Sorting by name is not the same as sorting by date

An unexpected sequence is not always caused by numeric sorting. First check which column or criterion is actually controlling the list.

A file manager may sort by name, modification date, file type, size, or another property. A photo application may use capture time from photo metadata. An import tool may use the order in which files were added. These choices can all produce a sequence that differs from the filename numbers.

For example, trip-003.jpg can appear after trip-010.jpg when the view is sorted by modification date, even though the names themselves would put 003 first. Renaming the files will not fix that view unless the application is actually using the filename as its sort key.

When order matters, identify both parts of the problem: what information expresses the order, and what information the current app is sorting by.

Dates in filenames have the same design problem

Dates are another case where the structure of the text affects sorting.

Suppose files use names such as:

report-9-1-2026

report-10-1-2026

The intended meaning may be clear to the person who created them, but text sorting has no universal reason to interpret those pieces as a calendar date. Date notation also varies between regions, making the meaning itself potentially ambiguous.

When chronological filename ordering matters, a year-first format with fixed-width month and day is much more predictable:

report-2026-01-09

report-2026-01-10

The most significant part, the year, comes first, followed by month and day. Each component also has a fixed width. As a result, ordinary ascending text order follows chronological order for dates written in this pattern.

This is useful for logs, exports, periodic reports, and folders that may be opened by different software. It also avoids relying on file modification times, which can change when files are copied, extracted, processed, or edited.

Mixed names can still produce surprises

Numbers are only one part of filename comparison. Capitalisation, punctuation, spaces, accented characters, and language-specific text can also affect ordering. Exact rules vary between operating systems and applications.

For that reason, it is risky to assume that every program will produce an identical alphabetical order for a complicated collection of names. A file manager may use language-aware comparison rules, while another tool may use a simpler comparison. Some programs may ignore or give special treatment to certain punctuation when presenting a list.

You usually do not need to know the underlying comparison algorithm. The practical lesson is simpler: if sequence is important enough that another person or another program must reproduce it, encode the sequence clearly rather than depending on subtle alphabetical behaviour.

A prefix such as 001-, 002-, and 003- is often easier to interpret than trying to make a mixture of words and punctuation sort in a particular way.

Renaming can change order without changing file contents

Adding a numeric prefix or leading zeros changes the filename, not the data inside the file. A photo remains the same image and a document keeps the same document contents.

However, filenames can matter to workflows around the files. Links, shortcuts, scripts, playlists, project files, or applications may refer to a file by its existing name or path. Renaming a large collection can therefore break those references even though the file contents are untouched.

Before batch-renaming files that are already used by another application, check whether that application tracks them by filename. This matters especially for project folders and media libraries where one file can refer to another.

For an independent set of exported photos or scanned pages, renaming is often straightforward. For files that belong to an active project, it deserves more care.

A practical naming pattern for ordered files

For a collection whose filename should define its order, keep the ordering part simple and fixed-width. A pattern such as:

001-introduction.pdf

002-installation.pdf

003-first-steps.pdf

makes the intended sequence visible to both people and simple text sorters. The descriptive part can still explain what each file contains.

If the order may exceed 999 items, choose more digits from the beginning. If it will never approach that size, three digits may be more than you need. There is no universal required width; the goal is to leave enough room for the sequence you expect.

Also remember that filename order is only useful when the receiving software actually sorts by filename. If an application deliberately sorts photos by capture date or songs by track metadata, changing filename prefixes may have no effect on the displayed order.

What to check when the order looks wrong

When numbered files appear out of sequence, start with the simplest explanation rather than assuming the files are damaged.

Check whether the view is sorted by name and whether the direction is ascending or descending. Then look at the names themselves. If the numeric parts have different widths, such as 2 and 10, the application may be using text-oriented sorting. Try a small test with 02 and 10 before renaming a large collection.

If the order is correct in one program but wrong in another, that is strong evidence that the programs are applying different sorting rules. In that situation, fixed-width numeric prefixes are often a more portable solution than trying to change each application’s preferences.

The useful mental model

A number written inside a filename is still part of a piece of text. Software may choose to recognise that text as a number for friendlier sorting, but it does not have to do so.

That explains why file-10 can sometimes come before file-2, why another app can reverse that surprise, and why leading zeros are so useful. If the order of a collection matters, make the order explicit in the filename and format its numeric parts consistently. You then depend less on how any particular program happens to interpret the names.