Windows – What happens when a computer “goes to sleep”

sleepwindowswindows 7

What happens when a computer goes to sleep? Should I sleep my computer or should I power it down? Is there an appropriate use for each mode or is it just a matter of personal preference?

Best Answer

I'll cover the three common states of a machine: sleep, hibernation, and powered off.


Sleep Mode

Sleep mode is essentially like taking a nap. Your computer is still on, but it is in a low-power state. It will consume less power and often disable hardware and suspend software to assist in reducing power consumption. This often involves disabling USB, PS/2, S/PDIF, audio, video, and other ports. Certain pieces of hardware, such as a wireless card, could also be disabled during this time.

The current session is stored in memory (RAM) and then the memory is placed in a low-power state. The memory still requires a current as otherwise it will decay and the session would be corrupted or lost entirely. During this time, the CPU is not executing any instructions; the storage mediums are also not doing anything.

When you resume the session (often by pressing the power button, moving the mouse, or tapping a key on the keyboard), the system immediately re-enables all of the previously disabled hardware and is pretty much ready to go. There will be a one or two second wait on any modern machine, but that's hardly anything to complain about.


Hibernation

Hibernation is a slower, prolonged version of sleep. It writes the contents of memory and other critical instructions for the system to resume the session to disk and then powers off the machine properly. This is not to be confused with sleep mode, as while hibernating the computer could be unplugged and moved around and still preserve the session. This is safer than sleep mode, but obviously when you turn the machine back on, it is going to have to go through power-on self-test (POST) and then restore RAM contents from disk. It does not, however, have to boot the OS again. And just as with Sleep mode, when it comes back up all the programs you had open will still be open and in the state you left them in.


Shutting Down

Powering a machine off is pretty obvious. In Windows (and other operating systems), a check is made to ensure that other users are not logged in and whatnot. Applications are also informed that the system is shutting down and can possibly stop the shutdown from occurring if something needs attention. Afterwards, the system logs out the users and then the system begins to "unload" critical system components that the operating system needs to run in the first place. After all of that has wrapped up, the operating system halts the machine; in other words, it stops power reaching the components in a safe manner.


Hybrid Sleep Mode

I would like to note that there is a "hybrid sleep mode" that basically combines both hibernation and sleep mode properties. The system will do both actions: write the instructions to disk and store them in memory and place the machine in a low-power state. However, in the event of power loss, the machine can just be turned on again properly and the session will be resumed. If the machine doesn't lose power, then the session should restore as if it was in sleep mode.


Security (of Sleep Mode)

EDIT: this was suggested in a comment. Thanks!

Another concern you might have is security.

As sleep mode is the only option where the machine is technically on, I'll only talk about that. As well, hibernation should lock the session whenever the machine is resumed anyway, as it requires a restart of the machine and operating system.

Obviously, someone coming along and continuing your session without permission is bad. However, by default on Windows operating systems (on some Linux desktop environments, and probably on OSX too), sleep mode should automatically lock the machine on session resume after a specific period of inactivity. If it isn't set to default (it might be my Windows image that has this), then it's easy enough to go into Power Options and change how Windows/OSX/Linux handles sleep mode.

As mentioned above, it is unlikely your network interfaces are active during the period of sleep. In theory, it would be impossible for any kind of network traffic to interact with your machine as the network interfaces should simply be powered off in the first place. In short, it shouldn't be a problem.

Typically, the only concern here is someone else having physical access to the machine. If you live in an environment where no one else will disturb it (or you don't mind them disturbing it), then there's not much of a security concern with using sleep mode.


What is Best

If you're asking "what is best", then I would argue that nothing is better than a healthy shutdown. Hibernation, while it DOES shutdown the machine, does not do other critical housekeeping measures (such as completely purging memory and killing zombie processes). By properly shutting down your system, you are essentially cleaning out the "gunk" that amasses throughout the life of a session. The longer your session lives (so, the more sleeps/hibernations your computer goes through) is often bad for the performance of the system. I won't delve into that further, though, as it is outside of the scope of this question.

If you just scrolled down to the bottom to read what someone thinks you should use, here you go: be patient and just shut down your system.

Related Question