If you've ever listened to a doctor over the course of your life, you've almost definitely heard the recommendation that you get a good, full night of sleep. You've also probably had days where you wake up groggy, tired and fuzzy. Other days you wake up bright and early, chipper and ready for the day.

What's going on? What's happening is you're experiencing sleep cycles, without knowing how they work or how to control them. A good night of sleep leaves you with more energy and a better mood. You have better memory and are better with critical thinking. You have faster reactions and you're refreshed when you wake up. If you don't sleep properly, all of that is the opposite.

Related: 3 Bad Sleep Habits You Need to Break

As an entrepreneur or CEO, sleep is perhaps more important than for anyone. You need to be at the top of your game to make important decisions for your business and you can't afford the losses that come with a lack of sleep. Yet, at the same time, there's a pervasive attitude that a successful entrepreneur is up late working, running on caffeine more than sleep.

There are more dangers than the immediate lack of energy and attention. Low-sleep lifestyles cause minor dysfunctions in the body that build up over time, and they don't all go away when you do get that one restful night a week. They build up and can come back as more prevalent diseases and a shorter lifespan years or decades down the line.

Thankfully, you can solve all of these problems just by learning how sleep works.

The science of sleep.

Sleep isn't like a computer, where it powers down for the night. Humans are much more complex machines. Sleep works in cycles that are divided into five stages. The first stage is light sleep, the kind of power nap sleep where you're barely asleep at all. You move, you shift, you doze. The second stage is deeper sleep with slower breathing, and the third stage is deeper yet, where your brain shifts into "defrag" mode and starts up maintenance. Stage four is even deeper and stage five is where you slip into REM sleep.

Related: The 7 Sleep Habits of Successful Entrepreneurs

REM sleep is the time where you dream and it's the sleep that is most beneficial to you. It's also the most detrimental if you wake up in the middle of it. The deeper you're sleeping when you wake up, the worse the negative effects.

One cycle of sleep tends to last around 90 minutes. REM sleep doesn't last for very long and you pull up out of it and back to stage one to repeat the process again. The trick, then, is to sleep in 90 minute multiples.

Now, I'm not saying you should jump into one of those four hours on three hours off cycles that trended for a while. Just make sure that the amount of time you spend asleep is a multiple of 1.5 hours. The "eight hours a night" is a myth; 7.5 hours is better, or nine. Waking up after eight will interrupt a cycle.

Unfortunately, it's very difficult to predict when you're going to fall asleep and thus when you need to wake up. If you have trouble falling asleep or if you get to bed late, you can't adjust your alarm on the fly. Or can you?

Related: Why Entrepreneurs Should Never Feel Guilty for Sleeping

As it turns out, there are a bunch of different apps for smartphones that monitor your sleep cycles. Remember how I said you tend to be restless and shift in stage one? Your phone's microphone can pick up the noise of shifting and the sound of lighter breathing. It can also possibly monitor tossing and turning with an internal gyroscope, depending on where you put your phone.

The way these apps work is you set a target time to wake up. It monitors your sleep cycles and locates the one where you pass into stage one sleep the closest to your target time, and wakes you up then. If all goes smoothly, you wake up refreshed, at the top of your game.

This, my friends, is the secret to sleep, and it's something all CEOs either already know or really need to learn.