A study published earlier this year in The Journal of Clinical Sleep Medicine shows that the relationship between better sleep and exercise may not be as black & white as one would think. To reach this conclusion study experts looked at data from a study of exercise and sleep where researchers had gathered a small group of people diagnosed with insomnia.

The researchers randomly assigned volunteers either to remain inactive or to begin a moderate endurance exercise program, consisting of three or four 30-minute exercise sessions a week for 16 weeks.

At the end of that time, the volunteers in the exercise group were sleeping much more soundly than they had been at the start of the study. They slept, on average, about 45 minutes to an hour longer on most nights, waking up less often and reporting more vigor and less sleepiness.

Researchers found that it takes up to four months for sleep patterns to improve. The results also showed that exercising for a shorter amount of time on the days after a poor night’s sleep helped study participants sleep better the next night.

It may seem counterintuitive – but most studies show that if you work out, fatiguing your body and mind, you sleep more soundly that night. But people with insomnia can be different because exercise can be such a physical demand. However, if the exercise program is maintained, sleep improves and levels of stress decrease.

Moral of the study: if you habitually experience insomnia and don’t currently exercise, start! But don’t expect an improvement overnight because it’s a gradual process.