Pigeons never seem to crash. While their less-fortunate cousins occasionally take down airplanes, the humble city pigeon darts between lampposts, dodges skyscrapers and dips around oncoming traffic with ease. Now scientists have captured some of that action on film—and figured out how pigeons manage to squeeze through particularly tight spaces.

Pigeons need to strike the perfect balance between safe and efficient flight. When maneuvering between two poles, for instance, they can choose to either raise their wings upward in a mid-flap pause, or fold their wings inward. The so-called “wing-pause” is the more efficient method — it costs very little energy and results in almost no altitude loss. Meanwhile, the “wing-fold” position saps more energy and loses more altitude, but it’s easily the safest way to protect delicate wings from an unforgiving lamppost.

After training four pigeons to fly back and forth across a flight corridor, scientists dropped obstacles into their flight paths to test whether each bird would use the wing-pause or wing-fold maneuver. When it came to tight spaces, the scientists found that the birds favored the less efficient wing-fold maneuver — presumably because, in those situations, there was a high probability of ramming into a pole. But for larger gaps (12 inches, or about half a wingspan), the pigeons were less concerned about a collision, and chose the riskier but lower energy wing-pause maneuver. From the paper:

The choice between these two postures seems mediated by an element of caution or uncertainty…the efficient flight strategy is chosen where gaps are wider and there is less chance of a collision occurring.

The findings may explain why, despite the millions of pigeons in New York City, we rarely see them smash into cars or telephone poles. Beyond that the research suggests that some birds tune their flight strategies, rapidly weighing the odds of making it through a narrow pass.