For a migratory bird, good timing is a matter of life or death.

Every spring countless warblers, geese, hummingbirds, and more—one in five bird species, all told—leave their winter hideaway on a long trek that eventually leads to mating, nesting and hatching chicks. Knowing when to leave is a delicate calculation for these animals, however. They need to reach breeding sites in plenty of time to successfully reproduce. But if they arrive too soon, winter may not have quite loosened its grip, which puts the birds at risk of starvation.

To time this arrival for the highest likelihood of conditions favorable to reproducing, a migratory bird tracks each day’s light length, or photoperiod, says Marilyn Ramenofsky, a behavioral endocrinologist at the University of California, Davis, who specializes in birds. That tracking happens instinctively in the animals, which use special photoreceptors in their brain to detect light. These receptors are similar to those that govern humans’ circadian rhythm. Though scientists don’t fully understand these light-sensing receptors, one team identified certain brain cells in quails that could directly detect light, according to a study published in 2014 in Current Biology.

In general, once those photoreceptors register that the days are lengthening in late winter and early spring, they trigger activity in a host of body systems.

Birds molt, for instance, shedding their worn feathers and growing new ones. Their hormones change, influencing their digestive patterns and leading them to eat more, put on weight and build up flight muscle. In some birds, once they’ve eaten enough, a digestive hormone called ghrelin begins to make them restless and nudges them to take flight. And the birds’ reproductive tracts begin to change in order to ensure that they will be fertile by the time they breed.

“It’s really a cabal of different endocrine systems that are shifting the bird from winter survival to migratory preparation,” Ramenofsky says.

When all the pieces fall into place, birds are well prepared to raise their chicks while making the most of the long days and the seasonal boom in bugs, berries and other resources their summer homes offer.

Each bird undergoes these seasonal changes a little bit differently. “They’re all sort of like little machines in terms of getting turned on, but there are individual decisions,” Ramenofsky says.

For example, a higher-quality winter habitat can delay an individual bird’s departure, says Ana M. González, an ornithologist at the government agency Environment and Climate Change Canada.

Weather conditions can be particularly important for timing, González says. She notes that birds may wait to depart until a storm passes. In addition, birds that are already en route can speed up or slow down their journey in response to the weather, which can help them time their arrival at breeding sites, González says.

Understanding migration is also complicated because the phenomenon comes in many forms. Some birds, such as Savannah Sparrows and American Woodcocks, migrate only short distances. Others, such as Cerulean Warblers and Red Knots, begin their prebreeding migratory journeys in the Southern Hemisphere, where days are getting shorter, not longer, and then cross the equator to reach North America.

Both scientists emphasized that researchers don’t yet understand the nuances that shape each species’ migration, much less each individual bird’s migratory timeline. “There’s a lot of variation [from] species to species and even within a species,” González says.

The return journey after breeding is even more of a puzzle. A day’s photoperiod seems to tie to the initiation of breeding steps, but by the time of the year when birds are returning, they are no longer sensitive to changes in day length, she adds. “The actual cue, we don’t know,” Ramenofsky says.

Fortunately, scientists’ tools for understanding migration are improving. Technology for tracking birds across long distances, particularly via satellite, is getting better. And community science initiatives—particularly the eBird program, which gathers reports of what species birders see where and helps scientists trace migratory pathways and schedules—are giving researchers many more eyes on birds.