Slacking on either sleep or exercise can even affect the other, according to sleep expert Dr. Charles Czeisler, reports Well+Good.

Here’s what happens when you stay up late and then rise early to hit the gym: Due to minimal sleep, your circadian rhythms shift, which means you’re “exercising during your biological night” when you should still be sleeping. According to Dr. Czeisler, that’s counterproductive because your muscle cells—which also have circadian rhythms—recover and perform better during your body’s biological daytime than they do during the biological night.

Obviously, working out when your whole body is awake is crucial when it comes to your muscles—and getting a proper amount of sleep also helps prevent injuries during exercise. In fact, a lack of sleep can weaken your immune system (which prevents you from working out) and can also lead to weight gain and health issues like cardiovascular disease and diabetes—i.e., precisely what exercise aims to prevent. But on the flip side, regular exercise promotes more restful sleep—so working out at the right time can actually bank you some quality shut-eye rather than curb it.