If you’re lying awake at night unable to sleep, the most effective thing you can do right now is get out of bed. That sounds counterintuitive, but it’s the foundation of the most evidence-backed insomnia treatment available. Beyond that single move, there’s a clear hierarchy of strategies, from same-night tactics to longer-term habit changes, that can reshape how you sleep.
Get Out of Bed After 15 to 20 Minutes
The worst thing you can do when you can’t sleep is stay in bed trying harder. Your brain starts associating the bed with frustration and wakefulness, which makes the problem worse over time. If you haven’t fallen asleep within 15 to 20 minutes, get up and move to another room.
Once you’re up, do something low-key for about 30 minutes before returning to bed. Reading, listening to a podcast, or light stretching all work. You can even do something enjoyable and mildly stimulating if that makes it easier to actually get up. The key rules: avoid computer monitors, smartphones, and tablets, since these blast blue-spectrum light close to your face (TV from across the room is generally fine). Don’t eat, exercise, or take a hot shower. Keep the lights dim so you don’t confuse your body’s internal clock. It helps to have a spot ready to go, maybe a chair with a blanket, reading glasses, and a book, so there’s zero friction when you need it. Repeat the cycle as many times as necessary until you fall asleep.
This technique is called stimulus control, and it’s one of the core components of Cognitive Behavioral Therapy for Insomnia (CBT-I), which is the first-line treatment recommended by sleep specialists over medication.
Fix Your Sleep Environment
Your bedroom temperature has a surprisingly large effect on sleep quality. The optimal range for adults is 60 to 67°F (15 to 19°C). Your core body temperature needs to drop slightly to initiate sleep, and a cool room helps that process along. If you tend to wake up sweating or kicking off covers, your room is probably too warm.
Darkness matters too. Blue light from screens suppresses your body’s natural sleep hormone for roughly twice as long as other types of light and can shift your internal clock by up to three hours. The practical recommendation is to avoid bright screens for two to three hours before bed. If that feels impossible, at minimum dim your devices and switch to warm-toned lighting in your home as the evening progresses.
Adjust Caffeine and Alcohol Timing
Caffeine has a half-life of four to six hours, meaning half the caffeine from your afternoon coffee is still circulating in your bloodstream at bedtime. One study found that caffeine consumed six hours before bed still disrupted sleep, even when people didn’t notice the effect. A reasonable cutoff for most people with a standard bedtime is 2 or 3 p.m.
Alcohol is trickier because it makes you feel drowsy initially but fragments sleep in the second half of the night. If you’re dealing with insomnia, even moderate evening drinking can make it significantly worse.
What CBT-I Looks Like
If your insomnia has lasted more than a few weeks, the gold standard treatment is Cognitive Behavioral Therapy for Insomnia. It’s a structured program, typically four to eight sessions, that retrains your sleep habits and thought patterns. The core components include stimulus control (the get-out-of-bed rule above), sleep restriction, managing sleep-interfering thoughts and arousal, adjusting food and substance intake, and resetting your biological clock.
Sleep restriction is the most counterintuitive piece. You temporarily limit your time in bed to match the amount of sleep you’re actually getting. If you’re lying in bed for eight hours but only sleeping five, you’d restrict yourself to a five-hour sleep window. This builds up sleep pressure, consolidates your sleep into a solid block, and then gradually expands. It feels rough for the first week or two, but it works remarkably well for most people.
CBT-I is available through sleep clinics, some therapists, and increasingly through digital programs and apps. It consistently outperforms sleeping pills in long-term studies because it addresses the root patterns driving insomnia rather than masking them chemically.
Where Melatonin and Magnesium Fit In
Melatonin is not a sedative. It’s a timing signal that tells your brain dusk has arrived. This makes it useful for circadian rhythm problems (jet lag, shift work, a sleep schedule that’s drifted late) but less effective for the classic “I’m tired but can’t fall asleep” insomnia. If you try it, take 1 to 3 milligrams two hours before your target bedtime. Many over-the-counter products contain 5 or 10 milligrams, which is far more than necessary and can cause grogginess.
Magnesium, particularly magnesium glycinate, is a popular supplement for sleep. Clinical trials have tested doses around 500 milligrams taken at night for several weeks. The evidence is more preliminary than for melatonin, but magnesium plays a role in nervous system relaxation, and many people are mildly deficient. It’s generally well tolerated and unlikely to cause harm at standard doses.
When Medication Makes Sense
Prescription sleep medications are typically reserved for short-term use or situations where CBT-I alone isn’t enough. The most commonly prescribed class includes drugs like Ambien and Lunesta, which work by slowing brain activity. They can help you get through an acute rough patch, but they come with real risks. In 2019, the FDA added warnings about complex sleep behaviors, including sleepwalking, sleep driving, and sleep cooking, some of which resulted in serious injuries.
A newer class of sleep medication works differently, blocking the brain’s wakefulness signals rather than sedating you. These tend to have a lower risk profile, though they’re not risk-free. For most people, medication works best as a bridge while building the behavioral habits that produce lasting results.
Check Whether Something Else Is Driving It
Insomnia isn’t always its own problem. It’s frequently a symptom of something else. Chronic pain, acid reflux, asthma, an overactive thyroid, diabetes, and heart disease can all disrupt sleep. So can sleep apnea, which causes repeated breathing pauses throughout the night. If you snore heavily, wake up gasping, or feel exhausted no matter how much time you spend in bed, sleep apnea is worth investigating.
Mental health conditions, particularly anxiety and depression, are tightly linked with insomnia. In many cases, treating the underlying condition resolves the sleep problem. If your insomnia started alongside other symptoms like persistent worry, low mood, weight changes, or increased heart rate, those clues help point toward the real issue.
Persistent insomnia lasting three or more months that doesn’t respond to the behavioral strategies above is worth evaluating with a clinician, ideally one who specializes in sleep medicine rather than one who will simply write a prescription.

