Your MacBook may not go to sleep correctly when you close the lid when, for example, an external monitor, USB keyboard or mouse prevents it. You'll find several programs designed to keep the laptop awake when the lid is closed as well. Removing or troubleshooting these hardware and software components can fix the problem.

External Components

If you have an external monitor, USB keyboard or mouse connected to your laptop, these devices may be keeping your computer awake when you close the lid by making the laptop run in clamshell mode. Clamshell mode enables you to use the computer with the lid closed, with the desktop displaying on your external monitor instead of the internal display. Remove the external components to see if this resolves the problem. If you're laptop goes to sleep with external components connected, it's possible to wake it up by pressing any button on the keyboard or mouse.

Programs

Certain programs installed on your MacBook could be preventing the laptop from going to sleep when the lid is closed. Programs like NoSleep, InsomniaX and SleepLess are designed to do just that. By uninstalling the program or disabling the setting within the program that keeps the computer awake, your MacBook will sleep once the lid is closed. If you need the laptop to stay awake when the lid is closed, keep these programs enabled.

Internet and Printing Issues

If your MacBook won't go to sleep only when connected to power, you may have Internet sharing enabled in your system preferences. Disabling Internet sharing over Wi-Fi should resolve the problem and enable the computer to sleep whenever the lid is closed. Check your print queue as well. If you have a print job that's stuck, clearing the print queue may resolve the problem.