Whether you jog to deal with stress or hit the gym to boost your mood, you know that the benefits of exercise go well beyond the physical. And now, a new study suggests that working out may help bolster your memory, too — but the timing is key. Researchers had 72 volunteers learn the locations and patterns of 90 objects on a screen, testing their memories after 40 minutes of viewing the screen. After that first test, they divided the volunteers into three groups. The first group exercised for 35 minutes on stationary bikes immediately, while the second got sent to a quiet room to watch nature documentaries before doing the same workout four hours later. The third group didn't exercise at all. Two days later, when the researchers tested all the volunteers' memories again (this time while they sat in an fMRI machine to measure brain activity), they found that those who exercised immediately remembered the screen about as well as those who didn't exercise at all. However, the group that waited to exercise four hours after memorising the screen performed the best out of the three groups. After comparing the participants' fMRI scans, the researchers also noted that the people who waited to exercise had stronger activity patterns in their brains' hippocampus, which is involved in memory, versus the other two groups. As Ars Technica notes, previous studies have linked molecules released in the brain during exercise, including dopamine, to aiding in the formation of long-term memories. This explains why working out in general might help you with retaining information. Since the researchers didn't test any other windows of time between learning and exercising, it's hard to say how long you should delay your workout in order to remember as much as possible. It also remains unclear whether this trick will help you remember anything for longer than two days. Of course, with summer in full swing, you might not be on the lookout for any cramming tips — but, this is a great trick to save for exam season.