To test this model, Dr. Couzin and Nigel Franks, an ant expert at the University of Bristol in England, filmed a trail of army ants in Panama. Back in England, they went through the film frame by frame, analyzing the movements of 226 ants. “Everything in the ant world is happening at such a high tempo it was very difficult to see,” Dr. Couzin said.

Eventually they found that the real ants were moving in the way that Dr. Couzin had predicted would allow the entire swarm to go as fast as possible. They also found that the ants behaved differently if they were leaving the nest or heading back. When two ants encountered each other, the outgoing ant turned away further than the incoming one. As a result, the ants headed to the nest end up clustered in a central lane, while the outgoing ants form two outer lanes. Dr. Couzin has been extending his model for ants to other animals that move in giant crowds, like fish and birds. And instead of tracking individual animals himself, he has developed programs to let computers do the work.

The more Dr. Couzin studies swarm behavior, the more patterns he finds common to many different species. He is reminded of the laws of physics that govern liquids. “You look at liquid metal and at water, and you can see they’re both liquids,” he said. “They have fundamental characteristics in common. That’s what I was finding with the animal groups — there were fundamental states they could exist in.”

Just as liquid water can suddenly begin to boil, animal swarms can also change abruptly thanks to some simple rules.

Dr. Couzin has discovered some of those rules in the ways that locusts begin to form their devastating swarms. The insects typically crawl around on their own, but sometimes young locusts come together in huge bands that march across the land, devouring everything in their path. After developing wings, they rise into the air as giant clouds made of millions of insects.

“Locusts are known to be around all the time,” Dr. Couzin said. “Why does the situation suddenly get out of control, and these locusts swarm together and devastate crops?”

Image A flock of European starlings in England. Credit... Ashley Cooper/Corbis

Dr. Couzin traveled to remote areas of Mauritania in Africa to study the behavior of locust swarms. Back at Oxford, he and his colleagues built a circular track on which locusts could walk. “We could track the motion of all these individuals five times a second for eight hours a day,” he said.