The first thing to hit Iain Couzin when he walked into the Oxford lab where he kept his locusts was the smell, like a stale barn full of old hay. The second, third, and fourth things to hit him were locusts. The insects frequently escaped their cages and careened into the faces of scientists and lab techs. The room was hot and humid, and the constant commotion of 20,000 bugs produced a miasma of aerosolized insect exoskeleton. Many of the staff had to wear respirators to avoid developing severe allergies. "It wasn't the easiest place to do science," Couzin says.

More from WIRED 21.04Platinum Age of TVNetflix Isn't Just Rebooting Arrested Development—It's Revolutionizing TVBuckle Your Brainpan: The Primer Director Is Back With a New FilmIn the mid-2000s that lab was, however, one of the only places on earth to do the kind of science Couzin wanted. He didn't care about locusts, per se—Couzin studies collective behavior. That's swarms, flocks, schools, colonies ... anywhere the actions of individuals turn into the behaviors of a group. Biologists had already teased apart the anatomy of locusts in detail, describing their transition from wingless green loners at birth to flying black-and-yellow adults. But you could dissect one after another and still never figure out why they blacken the sky in mile-wide plagues. Few people had looked at how locusts swarm since the 1960s—it was, frankly, too hard. So no one knew how a small, chaotic group of stupid insects turned into a cloud of millions, united in one purpose.

Couzin would put groups of up to 120 juveniles into a sombrero-shaped arena he called the locust accelerator, letting them walk in circles around the rim for eight hours a day while an overhead camera filmed their movements and software mapped their positions and orientations. He eventually saw what he was looking for: At a certain density, the bugs would shift to cohesive, aligned clusters. And at a second critical point, the clusters would become a single marching army. Haphazard milling became rank-and-file—a prelude to their transformation into black-and-yellow adults.

That's what happens in nature, but no one had ever induced these shifts in the lab—at least not in animals. In 1995 a Hungarian physicist named Tamás Vicsek and his colleagues devised a model to explain group behavior with a simple—almost rudimentary—condition: Every individual moving at a constant velocity matches its direction to that of its neighbors within a certain radius. As this hypothetical collective becomes bigger, it flips from a disordered throng to an organized swarm, just like Couzin's locusts. It's a phase transition, like water turning to ice. The individuals have no plan. They obey no instructions. But with the right if-then rules, order emerges.

Couzin wanted to know what if-then rules produced similar behaviors in living things. "We thought that maybe by being close to each other, they could transfer information," Couzin says. But they weren't communicating in a recognizable way. Some other dynamic had to be at work.

Rules that produce majestic cohesion out of local jostling turn up everywhere.

The answer turned out to be quite grisly. Every morning, Couzin would count the number of locusts he placed in the accelerator. In the evening, his colleague Jerome Buhl would count them as he took them out. But Buhl was finding fewer individuals than Couzin said he had started with. "I thought I was going mad," Couzin says. "My credibility was at stake if I couldn't even count the right number of locusts."

When he replayed the video footage and zoomed in, he saw that the locusts were biting each other if they got too close. Some unlucky individuals were completely devoured. That was the key. Cannibalism, not cooperation, was aligning the swarm. Couzin figured out an elegant proof for the theory: "You can cut the nerve in their abdomen that lets them feel bites from behind, and you completely remove their capacity to swarm," he says.

Couzin's findings are an example of a phenomenon that has captured the imagination of researchers around the world. For more than a century people have tried to understand how individuals become unified groups. The hints were tantalizing—animals spontaneously generate the same formations that physicists observe in statistical models. There had to be underlying commonalities. The secrets of the swarm hinted at a whole new way of looking at the world.

But those secrets were hidden for decades. Science, in general, is a lot better at breaking complex things into tiny parts than it is at figuring out how tiny parts turn into complex things. When it came to figuring out collectives, nobody had the methods or the math.

Now, thanks to new observation technologies, powerful software, and statistical methods, the mechanics of collectives are being revealed. Indeed, enough physicists, biologists, and engineers have gotten involved that the science itself seems to be hitting a density-dependent shift. Without obvious leaders or an overarching plan, this collective of the collective-obsessed is finding that the rules that produce majestic cohesion out of local jostling turn up in everything from neurons to human beings. Behavior that seems impossibly complex can have disarmingly simple foundations. And the rules may explain everything from how cancer spreads to how the brain works and how armadas of robot-driven cars might someday navigate highways. The way individuals work together may actually be more important than the way they work alone.

Blue jack mackerel merge into a bait ball, a torus that confuses predators. Christopher Swann/Science Photo Library

Aristotle first posited that the whole could be more than the sum of its parts. Ever since, philosophers, physicists, chemists, and biologists have periodically rediscovered the idea. But it was only in the computer age—with the ability to iterate simple rule sets millions of times over—that this hazy concept came into sharp focus.

How Swarms Emerge

Individuals in groups from neurons and cancer cells to birds and fish organize themselves into collectives, and those collectives move in predictable ways. But the ways those swarms, schools, flocks, and herds flip from chaos to order differ. Here’s a look at some of the behaviorial triggers. —Katie M. Palmer

Golden Shiners

Behavior: Seek darkness Presumably for protection, shiners search out dark waters. But they can't actually perceive changes in light levels that might guide their way. Instead, they follow one simple directive: When light disappears, slow down. As a result, the fish in a school pile up in dark pools and stay put.

Ants

Behavior: Work in rhythm When ants of a certain species get crowded enough to bump into each other, coordinated waves of activity pulse through every 20 minutes.

Humans

Behavior: Be a follower Absent normal communication, humans can be as impressionable as a flock of sheep. If one member of a walking group is instructed to move toward a target, though other members may not know the target—or even that there is a target—the whole group will eventually be shepherded in its direction.

Locusts

Behavior: Cannibalism When enough locusts squeeze together, bites from behind send individuals fleeing to safety. Eventually they organize into conga-line-like clusters to avoid being eaten. They also emit pheromones to attract even more locusts, resulting in a swarm.

Starlings

Behavior: Do what the neighbors do These birds coordinate their speed and direction with just a half dozen of their closest murmuration-mates, regardless of how packed the flock gets. Those interactions are enough to steer the entire group in the same direction.

Honeybees

Behavior: Head-butting When honeybees return from searching for a new nest, they waggle in a dance that identifies the location. But if multiple sites exist, a bee can advocate for its choice by ramming its head into other waggling bees. A bee that gets butted enough times stops dancing, ultimately leaving the hive with one option.

For most of the 20th century, biologists and physicists pursued the concept along parallel but separate tracks. Biologists knew that living things exhibited collective behavior—it was hard to miss—but how they pulled it off was an open question. The problem was, before anyone could figure out how swarms formed, someone had to figure out how to do the observations. In a herd, all the wildebeests/bacteria/starlings/whatevers look pretty much alike. Plus, they're moving fast through three-dimensional spaces. "It was just incredibly difficult to get the right data," says Nigel Franks, a University of Bristol biologist and Couzin's thesis adviser. "You were trying to look at all the parts and the complete parcel at the same time."

Physicists, on the other hand, had a different problem. Typically biologists were working with collectives ranging in number from a few to a few thousand; physicists count groups of a few gazillion. The kinds of collectives that undergo phase transitions, like liquids, contain individual units counted in double-digit powers of 10. From a statistical perspective, physics and math basically pretend those collectives are infinitely large. So again, you can't observe the individuals directly in any meaningful way. But you can model them.

A great leap forward came in 1970, when a mathematician named John Conway invented what he called the Game of Life. Conway imagined an Othello board, with game pieces flipping between black and white. The state of the markers—called cells—changed depending on the status of neighboring cells. A black cell with one or no black neighbors "died" of loneliness, turning white. Two black neighbors: no change. Three, and the cell "resurrected," flipping from white to black. Four, and it died of overcrowding—back to white. The board turned into a constantly shifting mosaic.

Conway could play out these rules with an actual board, but when he and other programmers simulated the game digitally, Life got very complicated. At high speed, with larger game boards, they were able to coax an astonishing array of patterns to evolve across their screens. Depending on the starting conditions, they got trains of cells that trailed puffs of smoke, or guns that shot out small gliders. At a time when most software needed complex rules to produce even simple behaviors, the Game of Life did the opposite. Conway had built a model of emergence—the ability of his little black and white critters to self-organize into something new.

Sixteen years later, a computer animator named Craig Reynolds set out to find a way to automate the animated movements of large groups—a more efficient algorithm would save processing time and money. Reynolds' software, Boids, created virtual agents that mimicked a flock of birds. It included behaviors like obstacle avoidance and the physics of flight, but at the heart of Boids were three simple rules: Move toward the average position of your neighbors, keep some distance from them, and align with their average heading (alignment is a measure of how close an individual's direction of movement is to that of other individuals). That's it.

Boids and its ilk revolutionized Hollywood in the early '90s. It animated the penguins and bats of Batman Returns. Its descendants include software like Massive, the program that choreographed the titanic battles in the Lord of the Rings trilogy. That would all be miraculous enough, but the flocks created by Boids also suggested that real-world animal swarms might arise the same way—not from top-down orders, mental templates of orderly flocks, or telepathic communication (as some biologists had seriously proposed). Complexity, as Aristotle suggested, could come from the bottom up.

The field was starting to take off. Vicsek, the Hungarian physicist, simulated his flock in 1995, and in the late 1990s a German physicist named Dirk Helbing programmed sims in which digital people spontaneously formed lanes on a crowded street and crushed themselves into fatal jams when fleeing from a threat like a fire—just as real humans do. Helbing did it with simple "social forces." All he had to do was tell his virtual humans to walk at a preferred speed toward a destination, keep their distance from walls and one another, and align with the direction of their neighbors. Presto: instant mob.

By the early 2000s, the research in biology and physics was starting to intersect. Cameras and computer-vision technologies could show the action of individuals in animal swarms, and simulations were producing more and more lifelike results. Researchers were starting to be able to ask the key questions: Were living collectives following rules as simple as those in the Game of Life or Vicsek's models? And if they were ... how?

Taking Shape

Changing simple parameters has profound effects on a swarm. By controlling only attraction, repulsion, and alignment (how similar a critter's direction is to that of its neighbors), researcher Iain Couzin induced three different behaviors in a virtual collective, all akin to ones in nature.—Katie M. Palmer

Disorder Alignment with only the closest neighbors produces ... nothing but a disordered swarm.

Torus Raise the alignment and the chaotic swarm swirls into a doughnut shape called a torus.

Flock Maximize alignment across the flock and the torus shifts; everyone travels in the same direction.

Before studying collectives, Couzin collected them. Growing up in Scotland, he wanted pets, but his brothers' various allergies allowed only the most unorthodox ones. "I had snails at the back of my bed, aphids in my cupboard, and stick insects in my school locker," he says. And anything that formed swarms fascinated him. "I remember seeing these fluidlike fish schools on TV, watching them again and again, and being mesmerized. I thought fish were boring, but these patterns—" Couzin pauses, and you can almost see the whorls of schooling fish looping behind his eyes; then he's back. "I've always been interested in patterns," he says simply.

When Couzin became a graduate student in Franks' lab in 1996, he finally got his chance to work on them. Franks was trying to figure out how ant colonies organize themselves, and Couzin joined in. He would dab each bug with paint and watch them on video, replaying the recording over and over to follow different individuals. "It was very laborious," he says. Worse, Couzin doubted it worked. He didn't believe the naked eye could follow the multitude of parallel interactions in a colony. So he turned to artificial ones. He learned to program a computer to track the ants—and eventually to simulate entire animal groups. He was learning to study not the ants but the swarm.

For a biologist, the field was a lonely one. "I thought there must be whole labs focused on this," Couzin says. "I was astonished to find that there weren't." What he found instead was Boids. In 2002 Couzin cracked open the software and focused on its essential trinity of attraction, repulsion, and alignment. Then he messed with it. With attraction and repulsion turned up and alignment turned off, his virtual swarm stayed loose and disordered. When Couzin upped the alignment, the swarm coalesced into a whirling doughnut, like a school of mackerel. When he increased the range over which alignment occurred even more, the doughnut disintegrated and all the elements pointed themselves in one direction and started moving together, like a flock of migrating birds. In other words, all these different shapes come from the same algorithms. "I began to view the simulations as an extension of my brain," Couzin says. "By allowing the computer to help me think, I could develop my intuition of how these systems worked."

By 2003, Couzin had a grant to work with locusts at Oxford. Labs around the world were quietly putting other swarms through their paces. Bacterial colonies, slime molds, fish, birds ... a broader literature was starting to emerge. Work from Couzin's group, though, was among the first to show physicists and biologists how their disciplines could fuse together. Studying animal behavior "used to involve taking a notepad and writing, 'The big gorilla hit the little gorilla,' " Vicsek says. "Now there's a new era where you can collect data at millions of bits per second and then go to your computer and analyze it."

Swarms of locusts. Mitsuhiko Imamori/Minden

Today Couzin, 39, heads a lab at Princeton University. He has a broad face and cropped hair, and the gaze coming from behind his black-rimmed glasses is intense. The 19-person team he leads is ostensibly part of the Department of Ecology and Evolutionary Biology but includes physicists and mathematicians. They share an office with eight high-end workstations—all named Hyron, the Cretan word for beehive, and powered by videogame graphics cards.

Locusts are verboten in US research because of fears they'll escape and destroy crops. So when Couzin came to Princeton in 2007, he knew he needed a new animal. He had done some work with fish, so he headed to a nearby lake with nets, waders, and a willing team. After hours of slapstick failure, and very few fish, he approached some fishermen on a nearby bridge. "I thought they'd know where the shoals would be, but then I went over and saw tiny minnow-sized fish in their buckets, schooling like crazy." They were golden shiners—unremarkable 2- to 3-inch-long creatures that are "dumber than I could possibly have imagined," Couzin says. They are also extremely cheap. To get started he bought 1,000 of them for 70 bucks.

When Couzin enters the room where the shiners are kept, they press up against the front of their tanks in their expectation of food, losing any semblance of a collective. But as soon as he nets them out and drops them into a wide nearby pool, they school together, racing around like cars on a track. His team has injected colored liquid and a jelling agent into their tiny backs; the two materials congeal into a piece of gaudy plastic, making them highly visible from above. As they navigate courses in the pool, lights illuminate the plastic and cameras film their movements. Couzin is using these stupid fish to move beyond just looking at how collectives form and begin to study what they can accomplish. What abilities do they gain?

For example, when Couzin flashes light over the shiners, they move, as one, to shadier patches, presumably because darkness equals relative safety for a fish whose main defensive weapon is "run away." Behavior like this is typically explained with the "many wrongs principle," first proposed in 1964. Each shiner, the theory goes, makes an imperfect estimate about where to go, and the school, by interacting and staying together, averages these many slightly wrong estimations to get the best direction. You might recognize this concept by the term journalist James Surowiecki popularized: "the wisdom of crowds."

But in the case of shiners, Couzin's observations in the lab have shown that the theory is wrong. The school could not be pooling imperfect estimates, because the individuals don't make estimates of where things are darker at all. Instead they obey a simple rule: Swim slower in shade. When a disorganized group of shiners hits a dark patch, fish on the edge decelerate and the entire group swivels into darkness. Once out of the light, all of them slow down and cluster together, like cars jamming on a highway. "That's purely an emergent property," Couzin says. "The sensing ability really happens only at the level of the collective." In other words, none of the shiners are purposefully swimming toward anything. The crowd has no wisdom to cobble together.

Flocks of Sheep Dariusz Paciorek/Getty

Other students of collectives have found similar feats of swarm intelligence, including some that happen in actual swarms. Every spring, honeybees leave their old colonies to build new nests. Scouts return to the hive to convey the locations of prime real estate by waggling their bottoms and dancing in figure eights. The intricate steps of the dances encode distance and direction, but more important, these dances excite other scouts.

Thomas Seeley, a behavioral biologist at Cornell, used colored paint to mark bees that visited different sites and found that those advocating one location ram their heads against colony-mates that waggle for another. If a dancer gets rammed often enough, it stops dancing. The head-butt is the bee version of a downvote. Once one party builds past a certain threshold of support, the entire colony flies off as one.

House-hunting bees turn out to be a literal hive mind, composed of bodies. This is no cheap metaphor. In the 1980s cognitive scientists began to posit that human cognition itself is an emergent process. In your brain, this thinking goes, different sets of neurons fire in favor of different options, exciting some neighbors into firing like the waggling bees, and inhibiting others into silence, like the head-butting ones. The competition builds until a decision emerges. The brain as a whole says, "Go right" or "Eat that cookie."

If a falcon attacks, all the starlings dodge almost instantly—even those on the far side of the flock that haven't seen the threat.

The same dynamics can be seen in starlings: On clear winter evenings, murmurations of the tiny blackish birds gather in Rome's sunset skies, wheeling about like rustling cloth. If a falcon attacks, all the starlings dodge almost instantaneously, even those on the far side of the flock that haven't seen the threat. How can this be? Italian physicist Andrea Cavagna discovered their secret by filming thousands of starlings from a chilly museum rooftop with three cameras and using a computer to reconstruct the birds' movements in three dimensions. In most systems where information gets transferred from individual to individual, the quality of that information degrades, gets corrupted—like in a game of telephone. But Cavagna found that the starlings' movements are united in a "scale-free" way. If one turns, they all turn. If one speeds up, they all speed up. The rules are simple—do what your half-dozen closest neighbors do without hitting them, essentially. But because the quality of the information the birds perceive about one another decays far more slowly than expected, the perceptions of any individual starling extend to the edges of the murmuration and the entire flock moves.

All these similarities seem to point to a grand unified theory of the swarm—a fundamental ultra-calculus that unites the various strands of group behavior. In one paper, Vicsek and a colleague wondered whether there might be "some simple underlying laws of nature (such as, e.g., the principles of thermodynamics) that produce the whole variety of the observed phenomena."

Couzin has considered the same thing. "Why are we seeing this again and again?" he says. "There's got to be something deeper and more fundamental." Biologists are used to convergent evolution, like the streamlining of dolphins and sharks or echolocation in bats and whales—animals from separate lineages have similar adaptations. But convergent evolution of algorithms? Either all these collectives came up with different behaviors that produce the same outcomes—head-butting bees, neighbor-watching starlings, light-dodging golden shiners—or some basic rules underlie everything and the behaviors are the bridge from the rules to the collective.

Stephen Wolfram would probably say it's the underlying rules. The British mathematician and inventor of the indispensable software Mathematica published a backbreaking 1,200-page book in 2002, A New Kind of Science, positing that emergent properties embodied by collectives came from simple programs that drove the complexity of snowflakes, shells, the brain, even the universe itself. Wolfram promised that his book would lead the way to uncovering those algorithms, but he never quite got there.

Couzin, on the other hand, is wary of claims that his field has hit upon the secret to life, the universe, and everything. "I'm very cautious about suggesting that there'll be an underlying theory that'll explain the stock market and neural systems and fish schools," he says. "That's relatively naive. There's a danger in thinking that one equation fits all." Physics predicts the interactions of his locusts, but the mechanism manifests through cannibalism. Math didn't produce the biology; biology generated the math.

Still, just about any system of individual units pumped with energy—kinetic, thermal, whatever—produces patterns. Metal rods organize into vortices when bounced around on a vibrating platform. In a petri dish, muscle proteins migrate unidirectionally when pushed by molecular motors. Tumors spawn populations of rogue, mobile cells that align with and migrate into surrounding tissues, following a subset of trailblazing leader cells. That looks like a migrating swarm; figure out its algorithms and maybe you could divert it from vital organs or stop its progress.

The same kind of rules apply when you step up the complexity. The retina, that sheet of light-sensing tissue at the back of the eye, connects to the optic nerve and brain. Michael Berry, a Princeton neuroscientist, mounts patches of retinas on electrodes and shows them videos, watching their electrophysiological responses. In this context, the videos are like the moving spotlights Couzin uses with his shiners—and just as with the fish, Berry finds emergent behaviors with the addition of more neurons. "Whether the variable is direction, heading, or how you vote, you can map the mathematics from system to system," Couzin says.

Crowds of humans. Amanda Mustard/Corbis

In a lab that looks like an aircraft hangar, several miles from Princeton's main campus, an assortment of submersibles are suspended from the ceiling. The cool air has a tang of chlorine, thanks to a 20,000-gallon water tank, 20 feet across and 8 feet deep, home to four sleek, cat-sized robots with dorsal and rear propellers that let them swim in three dimensions.

The robots are called Belugas, and they're designed to test models of collective behavior. "We're learning about mechanisms in nature that I wouldn't have dreamed of designing," says engineer Naomi Leonard. She plans to release pods of underwater robots to collect data on temperature, currents, pollution, and more. Her robots can also track moving gradients, avoid each other, and keep far enough apart to avoid collecting redundant data—just enough programming to unlock more complex abilities. Theoretically.

Today it's not working. Three Belugas are out of the tank so Leonard's team can tinker. The one in the water is on manual, driven by a thick gaming joystick. The controls are responsive, if leisurely, and daredevil maneuvers are out of the question.

Leonard has a video of the robots working together, though, and it's much more convincing. The bots carry out missions with a feedback-controlled algorithm programmed into them, like finding the highest concentrations of oil in a simulated spill or collecting "targets" separately and then reuniting.

Building a successful robot swarm would show that the researchers have figured out something basic. Robot groups already exist, but most have sophisticated artificial intelligence or rely on orders from human operators or central computers. To Tamás Vicsek—the physicist who created those early flock simulations—that's cheating. He's trying to build quadcopters that flock like real birds, relying only on knowledge of their neighbors' position, direction, and speed. Vicsek wants his quadcopters to chase down another drone, but so far he's had little success. "If we just apply the simple rules developed by us and Iain, it doesn't work," Vicsek says. "They tend to overshoot their mark, because they do not slow down enough."

Another group of researchers is trying to pilot a flock of unmanned aerial vehicles using fancy network theories—the same kind of rules that govern relationships on Facebook—to communicate, while governing the flocking behavior of the drones with a modified version of Boids, the computer animation software that helped spark the field in the first place. Yet another team is working on applying flocking behaviors to autonomous cars—one of the fundamental emergent properties of a flock is collision avoidance, and one of the most important things self-driving cars will have to be able to do is not run into people or one another.

So far, the Belugas' biggest obstacle has been engineering. The robots' responses to commands are delayed. Small asymmetries in their hulls change the way each one moves. Ultimately, dealing with that messiness might be the key to taking the study of collectives to the next level. Ever since the days of Boids, scientists have made big assumptions about how animals interact. But animals are more than models. They sense the world. They communicate. They make decisions. These are the abilities that Couzin wants to channel. "I started off with these simple units interacting to form complex patterns, and that's fine, but real animals aren't that simple," Couzin says. He picks up a plastic model of a crow from his bookshelf. "Here we have a pretty complex creature. It's getting to the point where we'll be able to analyze the behavior of these animals in natural, three-dimensional environments." Step one might be to put a cheap Microsoft Kinect game system into an aviary, bathing the room in infrared and mapping the space.

Step two would be to take the same measurements in the real world. Every crow in a murder would carry miniature sensors that record its movements, along with the chemicals in its body, the activity in its brain, and the images on its retina. Couzin could marry the behavior of the cells and neurons inside each bird with the movements of the flock. It's a souped-up version of the locust accelerator—combine real-world models with tech to get an unprecedented look at creatures that have been studied intensively as individuals but ignored as groups. "We could then really understand how these animals gain information from each other, communicate, and make decisions," Couzin says. He doesn't know what he'll find, but that's the beauty of being part of the swarm: Even if you don't know where you're going, you still get there.

Ed Yong (edyong209@gmail.com) writes the blog Not Exactly Rocket Science for National Geographic.