From the outside, it doesn’t seem like a sleeping baby is doing much. But beneath those heavy lids is a brain that’s working hard to make sense of the world—and especially those foreign words they constantly hear during waking hours.

When do babies understand words?

According to a new study, babies understand words as early as six months, which is sooner than previously believed. The funny thing is, the infants can’t always connect words and meanings. They only make the connections after a nap.

“Only during sleep, when the child’s brain is disconnected from the outer world, can it filter and save essential relations,” study lead Manuela Friedrich said in a press release.

For the study, researchers from the Max Planck Institute for Human Cognitive and Brain Sciences in Germany measured the word connecting abilities of 6 to 8 month olds by introducing them to fictitious objects given a silly name, such as “Bofel” or “Zuser.” This ensured the babies wouldn’t have used the objects or heard the words elsewhere. They then showed the kids objects that were the same, but were made in different colors. So, much like all cats are called “cats” regardless of their stripes, all zusers are called “zusers” regardless of their shade.

The researchers were monitoring the babies’ brain activities during all this and determined the infants were not able to connect a new object with a name they had already learned—meaning they didn’t recognize the new “zuser” as one even though they’d been introduced to one before.

This changed when the babies fell asleep: Those who fell asleep between the two lessons were able to make the connection, while the kids who stayed awake didn’t.

The length of the nap mattered, too. After a 30 minutes of sleep the kids were able to tell the difference between the right and wrong word for an object. But after 50 minutes of sleep, the babies were capable of a brain reaction that was previously only known for older children and adults. This showed the researchers that the sleepy babes had learned the meaning of the words.

Sleep and language acquisition

The study proves that babies are not only taking in stimuli when they’re awake, but also making sense of it and processing it during sleep.

Of course, we all knew sleep is super important for babies (and their parents, too). But now we know it is especially important in the development of memory and language. So the next time you’re tucking that sleepy little head into bed, be extra careful about what you say. Those may just be the words they remember.

A version of this story was originally published on August 10, 2017. It has been updated.