Sleep mode on Mac systems is useful for saving power while allowing you to quickly resume your work, and as a result is commonly used. You can use the Energy Saver system preferences to govern when the system goes to sleep, and you can also press the power button to invoke sleep behaviors. System sleep is governed by the power manager, which contains hardware variables that can either be set in the system preferences or by using tools such as the "pmset" terminal command.
The common sleep features can be accessed in the System preferences, such as setting when the system goes to sleep, and whether it will wake on LAN or modem access. Beyond these features, you can use the Terminal command "pmset" to adjust a number of additional features, such as setting the system to wake up if the power source is changed, change laptop display brightness when on battery power, and change the default sleep mode.
Sleep mode is useful, but there are times when a system may have problems either staying in sleep or going to sleep, which can happen for several reasons, including problems with software configurations, power management settings, and peripheral device malfunctions.
If your system cannot stay in sleep mode, then first try resetting the system's hardware settings, which include resetting the SMC (System Management Controller, or power manager), and the Parameter RAM (PRAM). Resetting these components will require a restart, after which you should then set up your sleep settings again using the Energy Saver system preferences. Try initially using minimal settings, such as only setting the sleep timer and avoiding scheduled wake-ups, and waking on administrator access.
Beyond hardware settings, problems with software configurations may also prevent a system from sleeping. Try quitting and disabling any third-party applications you have installed, especially those that run in the background or in the menu bar. Try booting to Safe Mode (hold shift at startup) to see if you can invoke sleep mode properly when in a minimal boot environment, and if so then further troubleshoot programs and settings on your system by systematically disabling them.
This may be particularly relevant for applications that install kernel extensions, as these may change how the system kernel interacts with the hardware. Unfortunately OS X does not have an extensions manager utility to manage and troubleshoot kernel extensions; however, you can uninstall them to troubleshoot and then reinstall them at a later point. In addition to Safe Mode, you can try creating a new user account on the system and logging into it (ensuring you log out of your current one) to see if Safe Mode works there. If so then you know a problematic setting in your main account was interfering with the system's sleep functions.
Lastly, if you have any peripheral devices attached to the system, try fully unplugging them and seeing if sleep mode works without them attached. Do this for your printers, secondary displays, and any other USB, FireWire, or Thunderbolt devices you have attached to the system. Then systematically attach them again and check to see if the system will sleep with each attached. You might also look into fully resetting and power-cycling your devices, as problems with hardware settings in them may contribute to the system not staying in sleep.
While you might be considering third-party devices, do not overlook the system's keyboard and mouse as well. Recently, MacFixIt reader Kent wrote in with a situation where apparent faults in the Apple keyboard were resulting in the system being triggered out of sleep, which apparently has happened to a few people's Apple keyboards. After using the utility PleaseSleep to keep the system in sleep mode, Kent found in the system logs that one of the keyboard's USB ports was issuing a wake-up command to the system, and if the keyboard was removed then the system would stay in sleep mode properly. In this case, changing the keyboard may be the only way to prevent the issue.