Four letters, four digits, and no rule about what comes first
Why Your Photos Are Not in the Order You Took Them
Open a folder of family photographs and something is almost always out of place. The christening sits after the funeral. Three frames from one burst arrive in the wrong sequence. A whole holiday lands at the top of a folder it has no business being in. The usual explanation offered is that the dates are wrong, and sometimes they are — but very often the dates are perfectly correct and the order is still wrong, because there is no standard anywhere that says what order you should be shown. We went and read the document that names your files to check.
What you actually noticed
The complaint is always specific. Not “my photos are disorganised” — that is a different and much larger subject — but something far more precise: these two pictures are the wrong way round. The one where the candles are lit comes before the one where they are not. The picture of everybody arriving is at the end. You know the real order because you were there, and the screen is telling you something else.
It is worth separating two things that feel identical and are not. One is a wrong date: the file genuinely claims to have been made in 1980, or last Tuesday, and the order follows obediently from a bad fact. That is a solvable problem and most of this site is about it. The other is the one in this article: the dates are fine, nothing is corrupt, nothing was edited — and the order is still not the order you took them in.
Knowing which of the two you have saves a great deal of pointless work, because they want opposite responses. One asks you to correct the evidence. The other asks you to stop trusting a sequence that was never promised to you.
The document that names your files
Every camera you have ever owned followed the same naming rules, and they come from a standard rather than from a house style. It is called the Design rule for Camera File system — DCF — published jointly as CIPA DC-009-2010 and JEITA CP-3461B. It is the reason a memory card from a Canon and a memory card from a Nikon have the same skeleton inside.
It starts with the folder. The standard defines a top-level directory and tells you, almost charmingly, what the letters mean:
Inside it, the folders are numbered. “The first three characters are a number between ‘100’ and ‘999’; numbers ‘000’ through ‘099’ shall not be used”, with the remaining five characters free — which is why you see 100CANON on one card and 101MSDCF on another. A maximum of 900 such folders may exist.
Then the file name itself, and this is the part that matters for order:
“The first four characters consist only of the upper-case alphanumeric characters… These are referred to as the DCF file name Free characters.”
“The four characters that follow are a number between ‘0001’ and ‘9999’. ‘0000’ shall not be used. These four digits are referred to as File number.”
So IMG_0421.JPG is four free characters the manufacturer chose and a four-digit counter the standard defines. That counter is the entire amount of sequence information a camera file name is capable of carrying. There is no date in it, no time, nothing about which card or which body it came from. Four digits, nine thousand nine hundred and ninety-nine of them available, and that is all.
The counter is a recommendation
Here is where most people’s mental model quietly breaks. The counter looks like a guarantee. It is not. The standard’s rule for choosing the next number is worded as advice:
Recommended. And in case that leaves any doubt, the standard’s own illustration of a typical folder is annotated with a four-word sentence that undoes every assumption built on top of file numbers:
Two more clauses finish the job. The first is the one that produces genuine duplicates on a single card: “Files may have the same name and number if they are in different DCF directories.” Two folders, two files called IMG_0421.JPG, both entirely legal, taken years apart. Anyone who has merged a card into a folder and been asked about replacing files has met this clause without knowing its name.
The second explains why counters sometimes appear to go backwards. A directory holds at most 9999 objects, and the number space is 0001 to 9999, so a long-lived camera must eventually start a new folder and begin again. Nothing is broken when that happens; the standard has run out of digits exactly as designed. But the practical effect is that a file numbered 0007 can easily be newer than one numbered 8431.
And there is one more clause that catches people during a tidy-up, because it is about copying rather than shooting: “Copying shall be treated in the same way as recording a new file.” A copy is a new recording. It is allowed to be given a new number, and on the date side it is allowed to be given a new date — which is a thread we pick up at the end.
Nobody specifies the order
At this point you might reasonably expect the standard to say something about how all this should be presented. It has a whole chapter on the subject — it calls the displaying device a “Reader” — and the chapter is remarkable for what it declines to do. Under the heading Playback method, section 6.1.1.2 consists of one sentence:
That is for directories. A page later, for files, section 6.2.2 says it again at greater length:
Read those two sentences together and the whole mystery dissolves. The camera industry agreed, in considerable detail, on where photographs go and what they are called. On the question of what order you see them in, it deliberately said nothing — twice, in two separate clauses, for two separate cases.
This was not an oversight. A standard that bound every camera back and every photo program on earth to one display order would have been unenforceable and probably unwise. But the consequence for you is concrete: there is no correct order to appeal to. When two programs show your photographs differently, neither of them is violating anything. They are both filling a silence.
So each program invents one
Given a free hand, every piece of software made a reasonable choice, and the choices do not agree.
Windows File Explorer sorts names the way a human reads them, which sounds obviously right and is more delicate than it looks. The function underneath is a documented part of Windows called StrCmpLogicalW, described as follows: “Compares two Unicode strings. Digits in the strings are considered as numerical content rather than text. This test is not case-sensitive.” It is the reason your files do not come out in the order a dictionary would give. Microsoft’s own documentation prints the contrast. Comparing digits by value gives this order:
While treating the digits as plain text — which is what a strict alphabetical sort does, and what plenty of other software still does — gives this instead:
Same nine names, two different orders, both correct by their own rule. Now substitute IMG_2.JPG and IMG_20.JPG and you have a very common complaint explained in one line.
And then there is the warning printed at the bottom of that same Microsoft page, which deserves to be better known than it is:
The maker of the sorting function your file manager uses says, in writing, that its results may change between versions of Windows and that it should not be relied on as the definitive order of anything. Between DCF declining to specify an order and Microsoft declining to stand behind one, the sequence on your screen has no authority behind it whatsoever. It is a presentation decision, made locally, revisable at any time.
Why the clock cannot break the tie
The obvious fix is to stop sorting by name and sort by time instead, and it is the right move — it is what we would tell anyone to do. It just does not resolve everything, for a reason buried in the Exif standard.
The capture time a camera writes is the DateTimeOriginal field, and in the current Exif specification — CIPA DC-008-2026, which we have gone through in detail elsewhere — it is a 20-byte ASCII string of the form YYYY:MM:DD HH:MM:SS. Whole seconds. There is nothing finer in the field.
Finer precision does exist, in a separate field called SubSecTimeOriginal (tag 37521). But its support level in the standard’s own table is O, for optional, at every level of conformance — and the standard provides for the case where a camera has nothing to say: “If the sub-second data is unknown, the entire area should be filled with blank characters.”
Put the two together. A camera shooting ten frames a second is required to record the second and merely invited to record the fraction. If it declines, six photographs from one burst carry six identical timestamps, and no amount of sorting by date can recover the order they were taken in, because that information was never written down. The program will fall back on something — usually the file name, which is where we came in.
None of which makes sorting by capture time a bad idea. It is far and away the best available order, and it is the only one that survives being copied to a new computer. It simply cannot do better than one-second resolution unless the camera chose to help.
Five causes, side by side
Five distinct reasons a folder of photographs comes out in the wrong order, what each one really is, and what to do about it.
| What you see | What is actually happening | Is anything broken? | What to do |
|---|---|---|---|
| IMG_20 before IMG_3 | The program is comparing digits as text, not as numbers — the second of the two orders in Microsoft’s own example | No. Both orders are documented behavior of different comparisons | Sort by capture date instead of by name, in any program that offers it |
| A burst in the wrong sequence | All the frames share one whole-second timestamp; the optional sub-second field was left blank | No. Exif records the second and only invites the fraction | Accept it, or set the order by hand for the handful of frames you care about |
| Two files with the same name | They came from different camera folders, which the standard explicitly permits | No, and this is the dangerous one — a careless merge overwrites one with the other | Never merge card folders by name. Copy whole folders, keep them separate, let software match on content |
| Numbers jump or restart | A new camera folder, a formatted card, or a counter that simply skipped — “numbers need not be consecutive” | No. The counter was never a guarantee of sequence | Stop reading the number as a position. It is a label, not a rank |
| Everything lands on one date | A copy, a download, a ZIP or a sync has replaced the file dates — “copying shall be treated in the same way as recording a new file” | Yes, in effect. Real information has been lost from the file system | Recover the capture dates from inside the pictures and write them back — see below |
Only the last row is a genuine loss. The other four are presentation, and they look like damage because nothing on screen ever admits that the order is being invented. If your folder is mostly the last row, our walkthrough on fixing wrong photo dates is the practical route out.
Five things widely repeated that are wrong
- “The file number tells you the order they were taken.” It does not, and the standard says so itself. Assigning the largest existing number + 1 is “recommended”, and the annotation on DCF’s own example folder reads “Numbers need not be consecutive.” A higher number usually means later. It never has to.
- “Two photos with the same file name means something has gone wrong.” It means they came from different camera folders. DCF states that “files may have the same name and number if they are in different DCF directories”. It is correct behavior, and it is the single easiest way to destroy a photograph during a tidy-up.
- “Alphabetical order is alphabetical order.” Not where digits are involved. Windows compares them as numbers; strict text comparison does not; Microsoft prints both results side by side. Software that shows you
IMG_20beforeIMG_3is not faulty, it is using the other comparison. - “Sorting by date is exact.” It is exact to one second. The Exif capture field is whole seconds and the sub-second field is optional, so photographs taken inside the same second have no recorded order at all. It is still the best sort available — just not an infinitely fine one.
- “If two programs disagree, one of them is wrong.” Neither is. DCF says “the order of playback is not specified” and, separately, that “no specification is made as to the playback display layout or order of display”. There is no standard order to be wrong about.
The part specific to dates
Everything above is about order. The reason we care about order is that it is the most visible symptom of something less visible, which is whether the date on a photograph is still true.
A sequence built on file names is fragile because file names are local and disposable. A sequence built on file system timestamps is worse, because of that one clause in DCF that applies to housekeeping rather than photography: “Copying shall be treated in the same way as recording a new file.” To the computer, a copy genuinely is new. It gets a new created date because on that drive it is new. A plain copy often carries the modified date across; a trip through a ZIP, a download, a cloud sync folder or a phone transfer frequently does not. Do that a few times across the years and the only thing your folder is sorted by is the history of its own moves.
The sequence that survives all of this is the one written inside the picture, because the capture time travels with the file wherever it goes. That is why getting real capture dates into your photographs is not a tidiness exercise but the thing that makes every future order trustworthy — including orders produced by programs that do not exist yet. It is the same conclusion we reached from the other direction when looking at why one photograph becomes five files: what is in the file lasts, what is around the file does not.
Two practical notes to finish. First, when the inside of the file has nothing to offer — a scan, a screenshot, a picture that arrived through a messaging app — the honest answer is evidence, not a guess: what the folder says, what the surrounding photographs say, what the person in the picture was wearing. A date reconstructed from evidence and recorded as such is worth having. A date invented to make a sort look tidy is not. Second, if the order you are fighting is the result of a move rather than a camera, what moving to a new PC does to your photos covers exactly what gets rewritten on the way across.
Where this comes from
- CIPA DC-008: the Exif standard itself — the date fields themselves, and that none of them is required.
- Unicode Standard Annex #15: normalization forms — why two filenames that look identical sort apart.
The order is the story
A library out of order is a library you stop opening, because nothing you look for is where it should be. Put the dates right and the years fall back into place.
Free Test Drive Buy NowFrequently asked questions
Why are my photos not in the order I took them?
Usually because no standard says what order you should be shown. The camera file naming standard, CIPA DC-009-2010, specifies the folder and the file name in detail but states in section 6.1.1.2 that the order of playback is not specified, and in section 6.2.2 that no specification is made as to the playback display layout or order of display. Every program therefore chooses its own order, most commonly by file name, and file names carry only a four-digit counter that the same standard says need not be consecutive. Switching to capture-date order fixes most of it, because that date is recorded inside the picture rather than invented by the program showing it to you.
What does the number in IMG_0421.JPG actually mean?
It is the DCF file number. The standard defines a camera file name as eight characters: four free characters chosen by the manufacturer, which is why one camera writes IMG_ and another writes DSC_, followed by a number between 0001 and 9999, with 0000 not permitted. That counter is the only sequence information the name carries. It contains no date, no time and nothing about which camera or card it came from.
Can two photos really have the same file name on one memory card?
Yes, and the standard says so explicitly: files may have the same name and number if they are in different DCF directories. A camera starts new numbered folders as it goes, so a card can legitimately hold two files called IMG_0421.JPG that were taken years apart. This is why merging card folders together by name is dangerous: the computer offers to replace one with the other and there is nothing obviously wrong to notice.
Why do my file numbers jump or start again at 1?
Because the counter was never a promise. The standard recommends assigning the largest existing number plus one, and then states that numbers need not be consecutive. A directory also holds at most 9999 objects and the number space runs only to 9999, so a long-lived camera must eventually begin a new folder and start counting again. Formatting a card, swapping cards and changing a camera setting can all reset or skip the count. A file numbered 0007 can easily be newer than one numbered 8431.
Why does Windows sort my photos differently from other software?
Because Windows compares digits by their numerical value rather than as text, using a documented function called StrCmpLogicalW. Microsoft's own documentation prints both results: comparing by value gives 2string, 3string, 20string, while treating digits as text gives 20string, 2string, 3string. Software using the second comparison will show IMG_20 before IMG_3. The same page also notes that the behavior of the function, and therefore the results it returns, can change from release to release, and that it should not be used for canonical sorting applications.
Why are burst photos in the wrong order even when I sort by date?
Because the Exif capture time is recorded to the whole second. DateTimeOriginal is a 20-byte string of the form YYYY:MM:DD HH:MM:SS, and the finer field, SubSecTimeOriginal, is listed as optional at every level of the specification, which also provides for it being filled with blank characters when the value is unknown. A camera taking ten frames a second may therefore write ten identical timestamps. When that happens the order the frames were taken in is not recorded anywhere in the files, and the program falls back on the file name.
What is the most reliable way to keep photos in order?
Sort by the capture date held inside the picture, and make sure that date is actually there. The capture time travels with the file through copies, drives and programs, whereas file names are local and file system dates are rewritten easily: the camera standard itself notes that copying is treated in the same way as recording a new file. For pictures with no capture date of their own, such as scans and screenshots, the durable approach is to establish the date from evidence and write it into the file, so that every program you use in future starts from the same fact.