Young sunflowers follow the sun, their still-green buds arcing from east to west across the summer sky as dawn turns to noon turns to dusk. Each night they reverse their dance, swinging from west to east in order to be the first to see the sun when it crests over the horizon at daybreak.

But do you know how they do it?

In a study published in the journal Science this past week, researchers say they’ve found an answer: Sunflowers, like animals, have a circadian rhythm – an internal clock that can be set to the external world. During the day, this system sends messages to the eastern sides of their stems, telling those cells to grow slightly longer, which causes the sunflower to lean westward. At night, the message reverses, and the sunflowers tilt back toward the east.

“It’s the first example of a plant’s clock modulating growth in a natural environment, and having real repercussions for the plant,” said Stacey Harmer, professor of plant biology at University of California-Davis and senior author on the paper.

Even though they don’t sleep, many plants have “clock genes” similar to those that direct the sleep-wake cycle in animals. For years, Harmer had been looking for a link between those genes and the release of a hormone that controls stem growth.

So Harmer tasked a graduate student with staking the sunflowers so they couldn’t move. The constrained flowers were smaller and frailer than the free-moving ones, proving that the flowers benefit from following the sun.

Then he moved some potted sunflowers into an indoor growth chamber, subjected to continual overhead lighting. For their first few days inside, the flowers continued to swing back and forth from east to west, just as you or I would maintain a more or less 24-hour sleep cycle during the first few days of living in constant light. This suggested that the flowers’ behavior was controlled by an internal rhythm, rather than a direct response to the sun.