Throughout the day, your internal clock rotates between sleep and wakefulness. This 24-hour sleep-wake cycle is known as our circadian rhythm.

Your internal clock is located in a part of the brain called the hypothalamus. It responds to external cues that tell your body it’s time to go to bed.

Sometimes, your circadian rhythm can get thrown off due to:

Luckily, there are things you can do to improve sleep hygiene and reset your internal clock.

Here are 12 ways to work your way back to a good night’s sleep.

One of the best ways to fix your sleep schedule is to plan your exposure to light.

When you’re exposed to light, your brain stops producing melatonin, the sleep hormone. This makes you feel awake and alert.

Darkness tells your brain to make more melatonin, so you feel drowsy.

In the morning, exposing yourself to light can help you wake up. Try opening the curtains, taking a walk, or relaxing on the porch.

At night, prime yourself for sleep by turning off or dimming bright lights. You should also avoid glowing electronic screens from computers, smartphones, or television, as they can stimulate your brain for several hours.

Making time for relaxation might help you sleep better.

When you’re stressed or anxious, your body produces more cortisol, the stress hormone. The higher the cortisol, the more awake you feel.

Creating a relaxing bedtime ritual may reduce stress and its negative effects on sleep.

Focus on calming activities, such as:

If your sleep schedule is out of whack, avoid naps during the day. Napping can make it difficult to go back to sleep at night.

Long naps might also cause grogginess, which is the result of waking up from deep sleep.

If you must nap, aim for less than 30 minutes. It’s also best to nap before 3 p.m. so your nighttime sleep isn’t disrupted.

One way to reset your internal clock is getregular exercise.

Most of your tissues — including skeletal muscle — are linked to your biological clock. So, when you work out, muscle responds by aligning your circadian rhythm.

Exercise also helps you sleep better by promoting melatonin production.

Thirty minutes of moderate aerobic exercise may improve your sleep quality that same night. However, you’ll get the best results if you exercise regularly. Aim for 30 minutes of moderate aerobic activity at least five times a week.

Keep in mind that evening exercise can overstimulate your body. If you want to exercise at night, do it at least one to two hours before bedtime.

A quiet sleeping environment is a must for a good night’s rest.

Your brain continues to process sounds, even as you snooze. Loud, distracting noises can make it difficult to fall asleep or stay asleep.

To remove loud noises, keep your television out of the bedroom and turn it off before bedtime. Turn off your cell phone or use the “silent” setting.

If you live in a noisy neighborhood, white noise can help you get quality sleep.

White noise is a soothing, steady sound that masks environmental noise. You can create white noise by using a:

  • fan
  • air conditioner
  • humidifier
  • air purifier
  • white noise machine

You can also wear ear plugs to block outside sounds.

Just before bedtime, your body temperature drops to prepare for sleep.

A cool bedroom temperature — between 60 and 67°F (15 and 19°C) — will help you feel comfortable and doze off.

Anything below 54°F (12°C) or higher than 75°F (24°C) might disrupt your slumber, so be sure to adjust your thermostat.

You can also use an air conditioner or fan during warmer weather, or a space heater during cold weather. These offer the extra benefit of creating white noise.

A comfortable bed is the best sleeping environment for a good night’s rest.

Old mattresses and pillows can cause aches and pains, making it difficult to get quality sleep.

Generally, experts suggest replacing your mattresses every 10 years and pillows every two years.

You should also get a new mattress or pillow if you wake up feeling stiff, or if you feel more comfortable sleeping on a bed away from home.

The firmness of your mattresses and pillows is up to you. But if your mattress is saggy and your pillows are lumpy, it’s time for a replacement.

Your circadian rhythm also responds to your eating habits.

A late dinner can delay sleep, so eat your last meal two to three hours before bed. This will give your body enough time to digest the meal.

Eating dinner around the same time each day will also get your body used to a routine.

It matters what you eat, too. Heavy, high-fat meals might disrupt sleep because they take a while to digest.

If you’re hungry, eat a light snack. The best foods for sleep include a combination of carbs and protein, such as wheat toast and almond butter.

Avoid caffeinated drinks like coffee, tea, or energy drinks. As a stimulant, caffeine takes several hours to wear off, so have your last cup before mid-afternoon.

It’s also best to skip alcohol before bed. A nightcap might make you drowsy, but alcohol actually disrupts your circadian rhythm, making it difficult to sleep well.

If you want to fix your sleep schedule, it helps to make one first.

Choose a bedtime and wake-up time. Stick to these times every day, even on weekends or days off. Try to avoid staying up or sleeping in for more than one to two hours.

By following a regular schedule, your internal clock can develop a new routine. Over time, you’ll be able to fall asleep and wake up with ease.

When you eat and digest food, your internal clock knows that you’re awake. That’s because metabolism and circadian rhythm are closely linked.

On the other hand, fasting puts your body on “standby” so it can repair itself. Fasting is also a normal part of sleep.

Try skipping food just before bedtime. Since fasting naturally happens during sleep, it may help you doze off.

Plus, your body continues to burn calories during sleep. If you fast before bed, you’re more likely to feel hungry in the morning. This might motivate you to rise early, then return to a normal sleep schedule over the next few days.

But remember, going to bed on an empty stomach can keep you awake. Fasting may be useful if you aren’t already hungry.

As mentioned earlier, melatonin is a hormone that regulates your sleep cycle.

Melatonin is normally made by the pineal gland in the brain, but it’s also available as a supplement. It can promote relaxation, so people with jet lag or insomnia often use it as a sleep aid.

At the proper dose, melatonin is generally considered safe. Always follow the instructions.

Possible side effects include:

If you’re taking other medications or have other health conditions, check with your doctor before using melatonin.

It’s normal to have sleep problems every now and then.

Usually, changing behaviors or habits can restore your routine. But if sleep troubles persist, visit your doctor.

You might have an undiagnosed sleep disorder. If so, a sleep specialist can guide you through proper treatment.

Shift work, all-nighters, and jet lag can mess with your sleep schedule. Fortunately, practicing good sleep hygiene can get you back on track.

Before bed, avoid bright lights and heavy meals. Make sure your sleeping environment is comfortable, quiet, and cool. During the day, stay active and skip naps so you can sleep better.

If you still can’t sleep well, visit to your doctor.