🧮 Formula breakdown
How the Sleep Duration Tracker calculates your results
This tracker turns your bedtime and wake time into a single thing: duration.
From there, it builds the three numbers that matter most for real life: a rolling average, a sleep debt estimate,
and a Consistency Score that rewards “steady” nights over “random” nights.
1) Nightly sleep duration (hours)
For each entry, the calculator converts your times into minutes after midnight. If your wake time is “earlier”
than your bedtime (for example, bedtime 11:30 PM and wake time 7:00 AM), the tracker assumes your sleep crossed
midnight and adds 24 hours to the wake time.
Duration (minutes) = (wake minutes + dayOffset) − bedtime minutes
Where dayOffset is 0 if wake time is after bedtime, and 1440 minutes
if wake time is earlier (meaning it’s the next day).
Then it converts minutes to hours:
Duration (hours) = Duration (minutes) ÷ 60
2) 7‑day and 30‑day averages (nights only)
The tracker separates “night sleep” from “naps” so the averages reflect your main sleep. (You’ll still see naps in
your history table and totals, but they don’t inflate your nightly average by default.)
For a window like 7 days, the calculator takes the most recent 7 days’ worth of night entries and computes:
Average = (sum of nightly durations) ÷ (number of nights logged)
If you logged fewer nights, it uses what you have — but your average becomes more reliable as your streak grows.
3) Sleep debt vs your goal
Sleep debt is not a perfect scientific concept, but it’s a very useful “reality check.”
The tracker asks: if your goal is G hours per night, how far are you above or below that goal across the last 7 nights?
Debt (hours) = (G × N) − (sum of durations over N nights)
If the number is positive, you’re below your goal (debt). If negative, you’re above your goal (surplus).
The tracker shows it as a friendly number like “+2h 30m debt” or “−1h 00m surplus”.
4) Consistency Score (0–100)
People often chase “more sleep” but ignore “more consistent sleep.” Your body loves rhythm.
So this tool turns your last 7 nights into a Consistency Score.
Step 1: compute the standard deviation (how spread out your nightly durations are).
If your nights are very similar, standard deviation is small. If your nights swing wildly, it’s big.
Step 2: convert deviation into a score:
Consistency Score = clamp(100 − (StdDevHours ÷ 2.5 × 100), 0, 100)
This maps about 0 hours deviation to ~100 score, and about 2.5 hours deviation to ~0.
Then we clamp it between 0 and 100.
What “good” looks like
- 90–100: Elite rhythm. Your sleep is extremely stable.
- 75–89: Solid consistency. You’ll usually feel “predictably okay.”
- 55–74: Normal life zone. Improvements here often boost energy fast.
- 0–54: Chaotic schedule. Your body is constantly re-adjusting.
Note: This is a simple tracker, not a medical device. But simple trackers win because you’ll actually use them.
🧪 Examples
Real examples you can copy
Example A: “I sleep enough but feel tired”
Imagine you hit around 8 hours some nights… but you also have 5-hour nights. Your weekly average might look fine,
but your Consistency Score will reveal the hidden problem: large swings.
- Mon: 8.0h
- Tue: 7.5h
- Wed: 5.2h
- Thu: 8.3h
- Fri: 6.1h
- Sat: 9.2h
- Sun: 7.8h
Your average is roughly 7.3h, but your schedule is “spiky,” so your Consistency Score may land in the 50–70 range.
Most people feel better fast by reducing the spikes (even without increasing the average).
Example B: “I’m building a sleep streak”
You choose a goal of 7.5h and keep your nights within ±20–30 minutes:
- 7.3h, 7.6h, 7.4h, 7.7h, 7.5h, 7.6h, 7.4h
Your Consistency Score will usually be very high (often 90+). Even if your average is “only” 7.5h,
many people report feeling more awake because their body can predict the pattern.
Example C: Cross-midnight math
Bedtime 11:45 PM, wake time 6:30 AM:
- Bedtime minutes = 23×60 + 45 = 1425
- Wake minutes = 6×60 + 30 = 390
- Wake is “earlier,” so we add 1440: 390 + 1440 = 1830
- Duration = 1830 − 1425 = 405 minutes = 6.75 hours
That’s 6 hours 45 minutes — and you can see exactly where the number comes from.
Example D: Naps
If you log a nap (say 1:20 PM → 1:55 PM), it will appear in your history and can raise your total sleep for the day,
but by default it won’t inflate your nightly averages or your Consistency Score (which is meant to reflect your main rhythm).