Skip to content
🛠️ToolsShed

Sleep Cycle Calculator

Calculate optimal sleep and wake times based on 90-minute sleep cycles.

About this tool

The Sleep Cycle Calculator helps you understand and optimize your natural sleep architecture by working with 90-minute sleep cycles. Sleep cycles are the body's natural rhythm, moving through light sleep, deep sleep, and REM (dream) sleep before repeating. Waking up at the end of a complete cycle leaves you feeling refreshed, while waking mid-cycle can leave you groggy and disoriented for hours.

To use this calculator, simply enter your desired sleep or wake time, and it will show you the optimal times to do the opposite. For example, if you need to wake at 7 AM, the tool calculates when you should fall asleep so that you complete full 90-minute cycles—suggesting times like 10:30 PM, 12:00 AM, or 1:30 AM. Whether you're planning a full night's sleep or a power nap, this approach helps align your sleep with your body's natural rhythm.

Frequently Asked Questions

Code Implementation

from datetime import datetime, timedelta

SLEEP_CYCLE_MINUTES = 90
FALL_ASLEEP_MINUTES = 14  # Average time to fall asleep

def wake_times_from_bedtime(bedtime: datetime, cycles: int = 5) -> list[datetime]:
    """Given a bedtime, return optimal wake-up times after N full 90-min cycles."""
    fall_asleep = bedtime + timedelta(minutes=FALL_ASLEEP_MINUTES)
    return [
        fall_asleep + timedelta(minutes=SLEEP_CYCLE_MINUTES * i)
        for i in range(1, cycles + 1)
    ]

def bedtimes_from_wake(wake_time: datetime, cycles: int = 5) -> list[datetime]:
    """Given a desired wake time, return bedtimes that allow N full 90-min cycles."""
    return [
        wake_time - timedelta(minutes=SLEEP_CYCLE_MINUTES * i + FALL_ASLEEP_MINUTES)
        for i in range(1, cycles + 1)
    ]

# Example: bedtime at 11 PM
bedtime = datetime.now().replace(hour=23, minute=0, second=0, microsecond=0)
print(f"Bedtime: {bedtime.strftime('%I:%M %p')}")
print("Best wake times:")
for t in wake_times_from_bedtime(bedtime):
    print(f"  {t.strftime('%I:%M %p')} ({(t - bedtime).seconds // 60} min)")

# Example: must wake at 7 AM
wake = datetime.now().replace(hour=7, minute=0, second=0, microsecond=0)
print(f"\nWake time: {wake.strftime('%I:%M %p')}")
print("Best bedtimes:")
for t in bedtimes_from_wake(wake):
    print(f"  {t.strftime('%I:%M %p')}")

Comments & Feedback

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