πŸ› οΈToolsShed

Sleep Cycle Calculator

Find the best bedtime or wake-up time based on 90-minute sleep cycles.

Sleep Cycle Calculator helps you plan your bedtime or wake time to align with your body's natural 90-minute sleep cycles. During sleep, your brain cycles through stages including light sleep, deep slow-wave sleep, and REM (dream) sleep. One full cycle takes approximately 90 minutes, and waking at the end of a cycle β€” rather than in the middle of deep sleep β€” means you wake feeling rested rather than groggy.

Enter either the time you want to wake up or the time you plan to go to sleep. The tool calculates bedtimes or wake times that fall at the end of a complete sleep cycle, accounting for the average 15 minutes it typically takes to fall asleep. Results for 4, 5, 6, 7, and 8 cycles are shown, covering roughly 6 to 12 hours of sleep.

Most adults need 7–9 hours of sleep, equivalent to 5–6 complete cycles. If you regularly wake up feeling tired despite sleeping the recommended duration, the problem may be timing β€” you are waking in the middle of a deep sleep phase. Adjusting your bedtime by 20–30 minutes can make a noticeable difference.

Frequently Asked Questions

Code Implementation

from datetime import datetime, timedelta

CYCLE_MINUTES = 90         # average sleep cycle length
SLEEP_LATENCY_MINUTES = 15 # average time to fall asleep

def wake_times(bedtime_str, num_cycles=6, latency_minutes=SLEEP_LATENCY_MINUTES):
    """
    Given a bedtime string ("HH:MM"), return suggested wake times
    for 3 to num_cycles complete sleep cycles.
    """
    bedtime = datetime.strptime(bedtime_str, "%H:%M")
    results = []
    for cycles in range(3, num_cycles + 1):
        sleep_duration = timedelta(
            minutes=latency_minutes + cycles * CYCLE_MINUTES
        )
        wake = bedtime + sleep_duration
        results.append({
            "cycles": cycles,
            "sleep_hours": round((cycles * CYCLE_MINUTES) / 60, 1),
            "wake_time": wake.strftime("%H:%M"),
        })
    return results


def bedtime_for_wake(wake_time_str, num_cycles=6, latency_minutes=SLEEP_LATENCY_MINUTES):
    """
    Given a target wake time, suggest when to go to bed for
    3 to num_cycles complete sleep cycles.
    """
    wake = datetime.strptime(wake_time_str, "%H:%M")
    results = []
    for cycles in range(3, num_cycles + 1):
        sleep_duration = timedelta(
            minutes=latency_minutes + cycles * CYCLE_MINUTES
        )
        bedtime = wake - sleep_duration
        results.append({
            "cycles": cycles,
            "sleep_hours": round((cycles * CYCLE_MINUTES) / 60, 1),
            "bedtime": bedtime.strftime("%H:%M"),
        })
    return results


# Example 1: bedtime β†’ wake times
print("If you go to bed at 23:00, wake up at:")
for w in wake_times("23:00"):
    print(f"  {w['cycles']} cycles ({w['sleep_hours']}h) β†’ wake at {w['wake_time']}")

# Example 2: target wake time β†’ bedtimes
print("\nTo wake up at 07:00, go to bed at:")
for b in bedtime_for_wake("07:00"):
    print(f"  {b['cycles']} cycles ({b['sleep_hours']}h) β†’ bed at {b['bedtime']}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.