Nearly every newborn parent has dealt with it: a crying baby that just won’t go to sleep, or an infant who wakes up in the middle of the night and won’t let anyone go back to bed.

Regardless of the countless hours of sleep lost, people have endless amounts of remedies and tricks to get a baby back to sleep. Now, researchers say they have figured out – scientifically – the best way to get a newborn back in their crib, and it involves moving around.

The findings, published Tuesday in the peer reviewed journal Current Biology, suggest the best method is to hold a crying baby and walk with them for five minutes. After that, researchers say to sit and hold the baby for five-to-eight minutes before putting them to bed. The walking-to-sit method even worked in the daytime, the results showed.

Researchers came to their conclusion be comparing 21 infant reactions to four scenarios: being held by walking mothers, held by sitting mothers, lying in a crib and lying in a rocking motion. 

The team found crying babies calmed down and heart rates slowed within 30 seconds of the mother walking and carrying. All babies stopped crying during this exercise, with half of them falling asleep, researchers said. Heart rates also slowed down when they were lying in a rocking motion. 

Pandemic babies: After years of stress, isolation affected brain development

Study: Stress levels during pregnancy linked to 3-month-old babies who cry, fuss more

However, when moms tried to put their baby back to bed after walking – but not sitting with them – one-third of the infants became alert within 20 seconds. Babies also had their heart rates go up and continue to cry when just held while sitting, but not carried while walking.