When you turn a phone sideways to take a photograph, the sensor does not turn with it. The pixels are recorded in the sensor's own orientation, which is whatever it physically is, and then the camera writes a small note in the file: this should be displayed rotated 90° clockwise.
The picture is not rotated. A note asking for it to be rotated is attached to it. Every piece of software that opens the file has to notice that note and act on it, and the ones that do not show you the pixels as recorded — on their side.
The tag
It lives in EXIF, the block of camera metadata attached to almost every photograph, and it is a single number called Orientation with eight defined values.
Only four are common: upright, rotated 90° one way, rotated 90° the other, and upside down. The other four describe mirrored versions, which arise from front-facing cameras and from scanners, and which almost nothing produces deliberately.
One number, eight possibilities, and a display that is either right or ninety degrees wrong depending on whether the software bothered to look.
Who reads it and who does not
Browsers read it — they have for years, in every engine. Phone galleries read it. Operating system previews read it. Modern image editors read it.
What does not read it, reliably, is anything older, anything minimal, and a surprising amount of server-side processing. Image libraries frequently decode the pixels and hand them on without consulting the tag, so an upload pipeline that resizes your photograph produces a correct-looking thumbnail that is sideways — or worse, a thumbnail that is upright while the original is not, because one stage read the tag and the next did not.
This is why the problem appears asymmetric and maddening. It is not the file changing. It is a chain of programs disagreeing about the same file.
The trap: stripping the metadata
This one catches people who are doing the right thing for the right reason.
You know that photographs carry GPS coordinates and camera serials, so you strip the EXIF before sending. Sensible. And the orientation tag is EXIF, so you have just removed the note — and the picture, which was never rotated, now displays on its side everywhere, including in the places that used to get it right.
The photo did not break when you stripped it. It was always sideways; the note was holding it up.
Any stripper worth using handles this: it applies the rotation to the pixels first, then removes the tag. That is what removing EXIF should mean, and it is worth checking rather than assuming, because a tool that simply deletes the block will silently turn every portrait photograph you own onto its side.
The fix that survives everything
Rotate the pixels.
Once the image is stored the way it should be displayed, the orientation tag is either absent or says "upright", and every program agrees — the ones that read the tag and the ones that never look. There is nothing left to disagree about.
Rotating is a real edit to the file rather than a change of note, which is precisely the point. Do it once, before uploading anything to a system whose behaviour you cannot predict, and the problem does not recur.
For a JPEG there is a lossless rotation — the 8×8 blocks are rearranged rather than re-encoded — but it only works when both dimensions are multiples of eight, which not every image is. A normal re-encode at high quality costs one generation and always works.
Why some uploads fix it and others break it
A site that resizes your upload has decoded the pixels, which means it had to decide about the tag. If it applied the rotation and saved the result upright, your photo is now permanently correct. If it ignored the tag and stripped the metadata while saving, your photo is now permanently sideways.
Both behaviours are common, neither is announced, and this is the whole explanation for why one platform "fixes" photos and another "breaks" them.
The short version
The tag is a note, not a rotation. Software that reads it shows the photo upright; software that does not shows what was recorded. Removing EXIF removes the note, so strip metadata only with something that applies the rotation first.
And if a photograph has to travel through systems you do not control, rotate the pixels before it leaves. It is the only state that means the same thing to everybody.