The first step you should take to sleep better is to make an appointment with your doctor. She should review all of the prescription and over-the-counter medications you take, a number of which—including blood pressure meds and a variety of antidepressants—can impair sleep.

Next, she should assess whether you have any medical conditions such as arthritis, heartburn, menopause, and prostate enlargement, all of which are notorious for interrupting sleep. But they’re often overlooked as contributing causes, says Marvin M. Lipman, M.D., Consumer Reports’ chief medical adviser.

Your doctor may also want to establish whether you suffer from sleep apnea (periodic pauses in breathing while you sleep, lasting from a few seconds to a few minutes) or restless legs syndrome (involuntary urges to move your legs). To do so, she will probably refer you to a sleep specialist who might track your patterns overnight, either at an inpatient sleep clinic or at home with a portable sleep monitor.

If your doctor rules out medical problems as a cause of your poor sleep, consider cognitive behavioral therapy for insomnia (CBT-I), a form of behavioral treatment that focuses on changing habits that disrupt sleep. The American Academy of Sleep Medicine now recommends CBT-I over sleep drugs as the treatment of first resort for chronic insomnia.

A 2015 review in the journal Annals of Internal Medicine concluded that CBT-I helped people sleep about 26 more minutes per night. Those improvements lasted even after the therapy stopped—and didn’t pose any of the risks that drugs do.

If you’re already taking sleeping pills, CBT-I has also been shown to help wean you from these drugs, says Lisa Medalie, Psy.D., an insomnia specialist at the University of Chicago. The treatment, which requires roughly two months of weekly sessions, is usually covered by insurance.

Here’s how it works: You’ll be asked to keep a sleep diary to record when you fall asleep and wake up, how long it takes to fall asleep (and if you wake up, how long it takes to fall back asleep), and how you feel the next day. Then the therapist will suggest strategies to help change your nagging thoughts and bad habits. At each session, you’ll get “homework,” such as stashing your smartphone under your bed at night so that you don’t obsessively check the time or your emails.

Personalized CBT-I is the most effective way to go, but you can start now by trying out some of the techniques a therapist might recommend.

Practice Makes Perfect

Healthy sleep habits should happen all day long, experts say.

A timeline to show you how to fall asleep the natural way

A top goal is to keep your body’s wake-sleep cycle predictable. Sleeping in some days feels good in the short term but creates long-term havoc.

Get your body into daylight early in the day if you can. That helps set a proper 24-hour clock.

Regular exercise encourages sleep, possibly because it tires you out and eases stress. Avoid working out within an hour or two of bedtime because that may increase alertness and make it more difficult to fall asleep.

A cup of coffee at breakfast or midmorning is okay, but if you have chronic trouble sleeping, avoid caffeine for at least 6 hours before bed.

Midday exposure to natural light helps strengthen your body’s 24-hour sleep-wake cycle.

Fight the urge for an afternoon snooze even if you didn’t sleep much the night before, for the same reason that you shouldn’t sleep in: When bedtime comes, you’re ready for sleep.

Big meals close to bedtime are a no-no, especially if you suffer from heartburn, which tends to worsen when you lie down. Alcohol is okay, as long as you will be up for several more hours. A drink before bed might help you conk out, but it can increase the likelihood of waking up in the middle of the night.

The blue light from laptops and smartphones can slow production of the sleep hormone melatonin. So shut them down 2 hours before you intend to go to sleep. Can’t unplug? At least dim the device and hold it a foot or so from your eyes. Or consider special glasses designed to block out blue light.

An hour or so before bed, dim the lights in your bedroom and do something relaxing: Read a physical book (not a lit screen), listen to quiet music, meditate, or have a glass of a warm, noncaffeinated drink. (Note that there might not be anything magical about milk, but any soothing drink before bed may help you unwind.)

Close your curtains, try eyeshades, use earplugs, or turn on a fan or a white-noise machine.

Watching the minutes tick by can become a self-defeating obsession. So put your alarm clock or smartphone someplace where you can’t easily see or reach it, such as under your bed.

 . . . and can’t get back to sleep within 20 minutes, go to another room and do something relaxing. When you start feeling sleepy, head back to bed.

Editor's Note: This article also appeared in the February 2016 issue of Consumer Reports magazine.

These materials were made possible by a grant from the state Attorney General Consumer and Prescriber Education Grant Program, which is funded by a multistate settlement of consumer fraud claims regarding the marketing of the prescription drug Neurontin (gabapentin).