Short answer: your external displays drop off while the Mac sleeps, macOS moves their windows onto the screen that is left, and when the displays come back it does not move the windows home. A longer display sleep timer, one monitor setting and two Mission Control settings stop it on many desks. On the rest, something has to remember the layout for you.
What actually happens while your Mac sleeps
You leave a tidy desk: browser on the big monitor, chat on the second one, notes on the laptop. You come back, wiggle the mouse, and everything is stacked on the MacBook screen with the two monitors sitting empty. You did not unplug anything, which is what makes it feel like a bug.
To macOS, though, something was unplugged. Many monitors, docks and hubs cut their video connection when they go into standby, and some take a few seconds longer than others to come back on wake. Each time that happens, the Mac sees a display disappear. It cannot leave windows on a screen that no longer exists, so it moves them to the screens that remain. When the display returns, macOS puts the screen back in its place in the arrangement but leaves the windows where it dropped them. It keeps no record of which window lived on which display.
This is the same thing that happens when you pull a cable out, which we explain in full in why Mac windows move when you unplug a monitor. Sleep just does the unplugging for you, at a time you are not watching.
Display sleep is enough to trigger it
The Mac does not have to go fully to sleep. When the screens switch off after a few idle minutes, that is display sleep, and many monitors drop their connection then too, while the Mac keeps running underneath. The same goes for locking the screen if it turns the displays off, or a screen saver that hands over to display sleep. That is why the scramble often shows up after a coffee break, not just overnight.
It also explains why it seems random. Whether you come back to a pile depends on how long you were away, whether the monitor reached its deepest standby, and which display happened to wake first. Two identical mornings can end differently.
Free fixes, in the order worth trying
1. Give the displays a longer display sleep timer. In System Settings > Lock Screen, set "Turn display off when inactive" (on a MacBook, the "on power adapter" one) to a longer time, or to never while you are at your desk. Fewer display sleeps means fewer chances to drop. The cost is power and, on some panels, burn-in risk from a static screen, so pair it with a lock you trigger yourself.
2. On a MacBook, keep the Mac awake when the display is off. In System Settings > Battery > Options, turn on "Prevent automatic sleeping on power adapter when the display is off." This does not stop the screens from sleeping, but it stops a full system sleep on top, which on many docks is the bigger disconnect.
3. Turn off your monitor's deep sleep. Plenty of monitors have an option in their own on-screen menu that makes them disappear from the Mac in standby. It goes by names like deep sleep, DisplayPort power saving, or auto input switching, and turning it off is one of the most commonly reported fixes for this exact problem. We have not tested every brand's menu, so the name and place vary: check your monitor's manual for anything about standby or power saving on the DisplayPort or USB-C input.
4. Set the two Mission Control settings. In System Settings > Desktop & Dock > Mission Control, turn on "Displays have separate Spaces" and turn off "Automatically rearrange Spaces based on most recent use," then log out and back in. On a Mac we tested, this was the difference between windows never returning to a reconnected display and always returning. It has tradeoffs (a window can no longer span two displays), covered in the unplugging guide.
5. Update the dock. If everything goes through a Thunderbolt or USB-C dock, check its maker's site for firmware updates. Docks that are slow to bring their displays back on wake are a common source of scrambles, and firmware is where that gets fixed.
If those stop it, you are done, and you do not need an app for this, ours included.
When the settings are not enough
Some desks keep scrambling anyway. The dock is slow to wake, the monitor has no deep sleep option, or the Mission Control tradeoff does not suit how you work. Then the fix is something that remembers where every window belongs and puts it back after the displays return. That is what Putback is for. Here is exactly what it does around sleep, taken from how version 1.3.3 is built:
It stops learning when the Mac goes to sleep. Putback learns your layout as you work. The moment macOS says it is going to sleep, it stops, and it does not start again until things have settled after wake. So the pile you wake up to is never saved as your new layout.
It puts everything back when the displays return. When your monitors drop and come back, macOS reports a display change. Putback waits for it to settle (half a second by default, adjustable in Settings), works out which desk you are at, and moves every window back to where it was on that desk. Each setup keeps its own memory, so the laptop-only layout and the desk layout never overwrite each other.
Pinned layouts get checked on every wake. Sometimes windows shift with no display change at all. If you pin a layout in Putback's Desks tab, Putback looks at it a couple of seconds after every wake and puts back anything that drifted, whether or not a display dropped.
And one shortcut covers the rest. Command-Shift-R (the default, and you can change it) restores the current desk any time, so if a wake ever slips through, it is one key, not five minutes of dragging.
Putback works on macOS 14 and later and has a free seven-day trial with no card. If you also want named layouts you can call up with a hotkey, apps and all, that is Scenes. And if you dock and undock a MacBook through the day, our multi-monitor guide covers that setup end to end.

