This is the spreadsheet that stopped me sleeping through alarms, with the working shown. Give it the time you have to be up and it counts back in sleep cycles to the bedtimes that end one right at the alarm.
I built it because "eight hours" never told me when to turn the light off. The alarm did, once I counted backwards from it.
How the math works
Sleep runs in cycles: light sleep, deep sleep, up into REM, and around again. The calculator takes your wake time, subtracts the minutes it takes you to fall asleep, then subtracts whole cycles. Six cycles, five, four, three. Each answer is a bedtime that ends a cycle right at the alarm, so it lands on a light patch instead of the middle of deep sleep.
The other direction works the same. Give it lights out and it adds the fall-asleep time, then adds cycles, and you get four wake times to choose from.
"I am going to sleep now" is the third mode, for the nights you have already lost the argument. It reads the clock and adds cycles from that moment. No fall-asleep time is added there, because you told me you are asleep now, and the clock starts when you say so.
The two assumptions are the ones I get asked about most, so they are sliders, not settings buried somewhere.
Cycle length is set to 90 minutes. That is an average, not a law. Carskadon and Dement's overview of normal sleep in Principles and Practice of Sleep Medicine puts the first cycle of the night at roughly 70 to 100 minutes and the later ones at roughly 90 to 120, so yours may be 70 or 110 and it changes through the night. The slider goes 80 to 100 because that is the band most people actually sit in.
Time to fall asleep is set to 15 minutes. Roughly 10 to 20 is usual for someone who is not sleep deprived and not lying there wired. If you are out in two, set it to 0. If you are still awake after forty, set it to 40 and read the last section.
The list stops at three cycles. Two cycles is three hours, and I am not going to put a number on the page that makes three hours look like a plan.
What the rows mean
The top row is the most sleep, six cycles, nine hours with the default settings. It used to carry a "Best" badge and I took it off, because none of the three panels I cite say nine hours is best for everyone. Every row now carries a mark instead: inside the recommended range for the age you picked, above it, or below it. Five cycles is seven and a half hours, and on a work night that is the row I use. Four is six hours: a short night with a plan. Three is a bad night with a plan, and knowing the number still beats guessing. Below the range is not a scolding. It is the number you have tonight. The big cell is the most sleep that still sits inside the range for the age you picked. At 65 and over nine hours is above that range, so the big cell is the 7 h 30 min row instead of the top one. When nothing in the list sits inside the range, no row gets the big cell, because I am not going to shout a time I have just marked as outside it.
The age select sits beside the sliders and starts on 18 to 64, so the page still answers before you touch anything. It changes no times at all. Move it and only the marks and the cited line under the list change, because a 15-year-old and a 40-year-old with the same alarm and the same cycle length get the same bedtimes. What differs is how many hours the research says to aim for, and that is a population range rather than your number.
Each row shows the clock time to turn the light off (or to set the alarm, in the other modes), the number of cycles, and the total sleep. The 24-hour toggle switches the display and remembers your choice on this browser; nothing else is stored.
Treat every row as a window, not a target. If it says 10:45 p.m., anything from about 10:30 to 11:00 is the same answer, because your cycles are not exactly 90 minutes and mine are not either. I wrote more about the studies behind the numbers in what time should I go to bed.
When to trust it and when not to
Trust it when your problem is that you go to bed at random times, or that the alarm keeps landing in deep sleep and you wake up thick and slow. That was my problem for most of my twenties, and counting cycles fixed it. Pick a row you can keep most nights and give it two weeks before you judge it.
Trust it less after a long flight, or on a rotating shift, or when the clocks change. Your body clock is somewhere else and the arithmetic does not know that. It still gives you a sane bedtime, but expect a rougher week than the rows suggest. Waffles, for what it is worth, ignores the clocks changing and wakes me at 5:40 either way.
Do not use it instead of a doctor. If you lie awake for an hour most nights, if you wake at 3 a.m. and cannot get back to sleep for weeks on end, if you snore hard enough to wake yourself, or if nine hours in bed still leaves you exhausted, those are not arithmetic problems. They may be insomnia or sleep apnea, and a calculator cannot see either. I am not a doctor, and I would rather say so twice than have you rearrange your evenings around the wrong number.