If you use more than one desktop on a Mac, you may have noticed that they don’t stay in the order you made them. Desktop 3 ends up second, the full-screen app you just left moves next to the one you’re in, and the three-finger swipe you know by heart takes you somewhere else. That’s a setting, and it’s on by default.
It’s called “Automatically rearrange Spaces based on most recent use”. Apple describes it as quicker access to the desktops you used most recently. Turn it off and the order you set stays put.
System Settings > Desktop & Dock > Mission Control
Automatically rearrange Spaces based on most recent use: off
An example of where this matters: you keep a browser on desktop 1, Terminal on 2 and mail on 3, and you move between them with Control-Left Arrow and Control-Right Arrow. With the setting on, a quick trip to desktop 3 can move it next to desktop 1, so the next Control-Right Arrow lands on mail instead of Terminal. With it off, the same key always goes to the same place. I’d switch it off the day you start using Spaces seriously; muscle memory needs a fixed map.
The caveat: you lose the convenience the setting was made for. If you mostly bounce between two desktops out of many, the automatic order did keep those two next to each other. It doesn’t change which desktop an app opens on; for that, look at Assign To in the app’s Dock menu.
Further reading: Change Desktop & Dock settings on Mac, Work in multiple spaces on Mac