When boa constrictors and other strangling snakes wrap their prey in a deadly embrace, they don’t just exert pressure on their victim; they put the squeeze on their own lungs as well. Now new research shows how these remarkable reptiles use a sophisticated breathing technique to avoid suffocating themselves.

Instead of using a diaphragm muscle to inflate their lungs as mammals do, snakes activate a series of muscles around their extremely long rib cage. But crushing a struggling animal restricts these muscles, and scientists have long puzzled over how the snakes survive this constriction contradiction.

A team of researchers, led by John Capano of Brown University, reports in the Journal of Experimental Biology that boa constrictors can selectively move individual rib muscles in whatever parts of their chest are unblocked at a given moment. This lets small areas of the lungs function like a pump, sucking air through the constricted zones to absorb as much oxygen as possible. “Oftentimes, when they’re not ventilating with that [squeezed region of the lung], it’ll be more or less entirely collapsed,” Capano says.

To discover this process, the researchers wrapped boa constrictors with blood pressure cuffs to prevent certain parts of their chests from expanding. Then they measured respiratory flow using small masks strapped to the reptiles’ snouts. Unfortunately, the snakes proved to be mask skeptics. “One of the big challenges was really just getting the animals to perform in the lab setting,” Capano says.

But the researchers eventually saw how the snakes used selective breathing to take in adequate air despite the cuffs. Recordings of electrical activity and x-ray images confirmed that nerve impulses strategically activated specific muscles in free areas. The snakes did not even attempt to breathe with the restricted parts of their rib cage—instead they exclusively used muscles on ribs that could still move. The researchers suggest this ability developed early in the snakes’ evolutionary history because it would have let them swallow ever larger prey.

“The authors made really clever biomechanics experiments,” says Eletra de Souza, a snake researcher at the University of São Paulo, who was not involved in the study. “The bony and morphological adaptations of snakes always surprise me. It’s amazing to see how these animals cope so well in the absence of limbs.”