Ants have a strategy when facing a flood.

A new study published in PLOS ONE reveals that flood ants (Formica selysi) build rafts out of their own bodies to survive. The ants link themselves together, placing the valuable queen in the middle while the rest of the brood, including larvae and pupae, are at the bottom of the raft.

“We were expecting the colonies to protect the most valuable members, the queen and young,” study leader Jessica Purcell, an ecologist at the University of Lausanne in Switzerland, told National Geographic.

Instead, researchers were surprised to discover that the ants placed their babies on the bottom of the raft since they were more efficient. And in the end, fewer lives were lost had older members taken their place, Purcell said.

The study involved observing ants collected from a flood plain in Switzerland. In a lab environment, different combinations of ant populations were “flooded,” and researchers could observe which members were placed where in the raft. Scientists found that once the region begins to flood, worker ants will grab larvae and use them as a floatation device.

“The larvae and pupae are buoyant and not entirely submerged,” said Purcell. “They are also quite fat, which may be one characteristic that helps buffer them against cold-water conditions.”

Researchers found the worker ants and brood were resistant to submersion. Both had high survival rates after they were on the raft, which may mean the base of the raft isn’t as dangerous as it seems. Researchers also found if the larvae and pupae were not under the raft, 25 percent to 50 percent of the worker ants experienced some contact with the water, putting them in more danger.

Ants aren’t the only insects that can join forces to survive. Japanese honeybees, leafcutter ants and termites are also known to collaborate for self-preservation.

The latest study is one of the first to understand how flood ants operate.

“It was an interesting contribution. No one had really looked at this idea of the brood as a flotation device,” David Hu, a mechanical engineer at the Georgia Institute of Technology who was not involved in the study, told the Los Angeles Times. “It adds a level of sophistication to the rafts that was previously not understood.”