DEV Community

Farbod F.
Farbod F.

Posted on

90-minute sleep cycles: the simple math behind bedtime calculators

90-minute sleep cycles: the simple math behind bedtime calculators

Sleep calculators look like magic: you type in the time you want to wake up, and they hand you a list of bedtimes like 10:45 PM, 12:15 AM, 1:45 AM. The gaps between those times are always 90 minutes, and that's the whole trick. Sleep isn't one long block — it's a series of roughly 90-minute cycles, and waking up at the end of a cycle feels very different from waking up in the middle of one.

The model in one paragraph

Each cycle runs through light sleep, deep sleep, and REM, then starts again. The average cycle is about 90 minutes, so a night's sleep is really a count of cycles: 4 cycles is 6 hours, 5 cycles is 7.5 hours, 6 cycles is 9 hours. A sleep calculator works backwards from your wake-up time, subtracting whole cycles, and then subtracts the time it takes you to fall asleep — about 15 minutes for most people. That's it. No sensors, no AI, just subtraction.

The worked example: waking up at 6:30 AM

Say you need to be up at 6:30 AM. Working backwards with 90-minute cycles and a 15-minute fall-asleep time:

  • 6 cycles (9 hours of sleep): asleep by 9:30 PM, so in bed by 9:15 PM
  • 5 cycles (7.5 hours): asleep by 11:00 PM, so in bed by 10:45 PM
  • 4 cycles (6 hours): asleep by 12:30 AM, so in bed by 12:15 AM

Notice the pattern: the bedtimes are 90 minutes apart, and every one of them lands you at 6:30 AM at the end of a cycle. The same math runs forward, too. In bed at 11:00 PM, asleep around 11:15 PM, and your cycle boundaries fall at 12:45, 2:15, 3:45, 5:15, and 6:45 AM. Set the alarm for 6:45 and you get 5 full cycles; set it for 6:00 and you wake up 45 minutes into a cycle.

The surprising part: 7 hours can feel worse than 6

Here's the figure that makes people rethink their alarm. Seven hours of sleep is 420 minutes — that's 4 full cycles (360 minutes) plus 60 minutes into cycle 5. Sixty minutes into a cycle is roughly when you're in deep sleep, the hardest phase to wake from. So a 7-hour night can leave you groggier than a 6-hour night that ends exactly on a cycle boundary. More sleep isn't automatically better sleep; where the sleep ends matters as much as how long it lasts. That 6:00 AM alarm after a 11:15 PM sleep onset? It catches you 45 minutes into cycle 4 — also mid-cycle. Shifting it to 5:15 or 6:45, both cycle boundaries, costs nothing and can change how the whole morning feels.

The code: about 30 lines

const CYCLE_MINUTES = 90;
const FALL_ASLEEP_MINUTES = 15;

function bedtimesFor(wakeUp, cycles = [6, 5, 4]) {
  return cycles.map((n) => {
    const asleep = new Date(wakeUp.getTime() - n * CYCLE_MINUTES * 60000);
    const inBed = new Date(asleep.getTime() - FALL_ASLEEP_MINUTES * 60000);
    return { cycles: n, sleepHours: (n * CYCLE_MINUTES) / 60, inBed };
  });
}

const wakeUp = new Date();
wakeUp.setHours(6, 30, 0, 0);
for (const t of bedtimesFor(wakeUp)) {
  console.log(
    `${t.cycles} cycles (${t.sleepHours}h): in bed by ` +
    t.inBed.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
  );
}
// 6 cycles (9h): in bed by 09:15 PM
// 5 cycles (7.5h): in bed by 10:45 PM
// 4 cycles (6h): in bed by 12:15 AM
Enter fullscreen mode Exit fullscreen mode

The same function runs forward if you give it a bedtime instead: add the fall-asleep time, then add cycles in 90-minute steps, and you get the wake-up times that land on a boundary. The only inputs are the anchor time and the cycle count — everything else is arithmetic.

Honest caveats

This model is a useful approximation, not a measurement. Real sleep cycles run roughly 70 to 120 minutes, not exactly 90, and they tend to get shorter and more REM-heavy toward morning. Your fall-asleep time isn't a constant 15 minutes either — it varies with stress, caffeine, light, and the day you had. Adults generally need 7 to 9 hours, so regularly choosing 4 cycles (6 hours) because the math looks neat is a bad trade; the calculator tells you when to sleep, not how little you can get away with. And if you consistently can't fall asleep, wake up constantly, or feel exhausted despite full nights, that's a conversation with a doctor, not a JavaScript function.

The point of building the calculator isn't that 90 minutes is a law of nature. It's that a tiny model — one constant, one subtraction — turns a vague "go to bed earlier" into a specific time you can actually act on. You can try the working version here: the sleep calculator (https://youcancalc.com/calculators/sleep-calculator/) on youcancalc.com does exactly this math, forward from a bedtime or backwards from a wake-up time.

Top comments (0)