I have long been fascinated by the homes that animals construct. Over the years I have contemplated the nests of hundreds of different species—including ants, termites, wasps, birds, fish and mice—by poking and prodding nests in the wild, manipulating them in the laboratory and reviewing the work of other scientists. I have dug holes meters deep, trying to find the bottoms of ant nests. I have snorkeled over bluegill fish, watching them excavate and tend to their dish-shaped nests. As a boy, I even tried to swim up into a beaver lodge.

In studying these homes, I have encountered an astonishing diversity of forms. Some nests are long, straight tunnels. Some are branching labyrinths. Others spin in wild helices or take on elaborate fractal forms. But what I find most remarkable about each construction is that it evolved. Each type of nest is just as integral a part of the species and individuals that made it as the animals' limbs, eye color, skin covering and genes. Indeed, the instructions to build nests must be, at least in part, inscribed in the genes of the animal kingdom's architects.

Only now are biologists finally beginning to understand how such architecture evolved. Recent research has started to pinpoint some of the genes responsible for nest-building behavior, reveal the physics underlying the shapes of different animals' nests and even explain the way that some puny-brained critters work together to construct entire metropolises. Like many good stories, this one begins in a garage.

A House for a Mouse
In 2003 Hopi e. Hoekstra was a young scientist, then at the University of California, San Diego, trying to uncover the links between genes and the behavior of mice. She already knew that different kinds of mice build differently shaped tunnels. Jesse N. Weber, then a student in Hoekstra's lab, began to wonder if he and Hoekstra could find the genes associated with building one type of nest rather than another.

Weber's first task was to craft indoor enclosures that were large enough and held enough dirt to entice mice to dig tunnels. He improvised, building cages out of plywood, nails, playground sand, and other inexpensive and easily accessible materials. Because no lab space was available for the project, he built the cages in the garage attached to Hoekstra's home. The results were ugly but effective: a series of sheds held together by duct tape and ambition.

Hoekstra was already studying field mice in the genus Peromyscus, so Weber decided to fill these cages with two Peromyscus species: oldfield mice (P. polionotus) and deer mice (P. maniculatus). Deer mice, which live across much of North America (except the far Southeast), dig a single, short tunnel, whereas oldfield mice, which live exclusively in the far Southeast, dig a long tunnel with a branching escape route that dead-ends just below the soil surface.

When scientists studying lab mice want to find the gene behind a particular trait, they often mate mice that do have that trait with those that do not and see which of those parents the offspring resemble. If the new generation has the trait, it might just be encoded by a dominant version of a single gene, a bossy allele. This trick—the same one Gregor Mendel used on his pea plants—works best for relatively simple relations between genes and traits. Tunnel building did not seem likely to be a simple trait encoded by one gene, but Weber gave the approach a try, anyway. Oldfield and deer mice do not mate in the wild, but, as they say, what happens in the garage stays in the garage. Weber got the mice to mate; he then allowed the resulting progeny to dig.

The most probable scenario was that the tunnels of the hybrid mice would be a complex amalgam of those built by their parents, the middling mélange of genetic complexity. Instead this first generation of hybrid mice all built long tunnels with escape hatches. In theory, this pattern could result from simple dominance involving as few as two genes: one associated with tunnel length and the other with the escape hatch. Inheritance of one or two dominant versions of the tunneling gene from an animal's parents would yield long tunnels; likewise for the hatch gene. Only two recessive versions of either gene would result in truncated tubes or no escape hatch. But Weber and Hoekstra thought such simplicity unlikely.

Yet when they crossed the hybrid mice with the oldfield mice (a backcross), they were surprised to find something akin to what might be expected from simple dominance, at least for escape tunnels. About half the progeny built escape routes, and half did not. Tunnel length, in contrast, varied continuously, suggesting more complexity. In follow-up work, Weber, now a postdoctoral fellow at the University of Texas at Austin, and Hoekstra, now a professor at Harvard University, ultimately identified the particular regions of the mouse genome associated with each attribute. Escape-hatch building is controlled by a group of genes, or even just one gene, on a single chromosome. Tunnel length appears to be governed by several genes scattered among three parts of the genome, which would explain the greater complexity observed in Weber's crosses.

Weber and Hoekstra's work demonstrated that even in smart animals, such as mice, complex behaviors involved in nest construction can be both genetically encoded and a product of evolutionary forces. With this discovery, Weber and Hoekstra pulled a string loose from an enormous ball of yarn. To unravel the rest of the ball, Weber, Hoekstra and other scientists will have to repeat similar experiments for each of the tens of thousands of species that build. Scientists in Russell Fernald's lab at Stanford University are already exploring the genes underlying nest design in cichlid fish in which some species make divot nests and others make mounds. More studies will follow.

The genetics of building in some animals will no doubt prove more complex than in field mice. Some species, such as canaries, learn how to build—or, in the case of bowerbirds, decorate—their constructions by mimicking their parents and peers. Others, such as many social insects, are difficult to breed properly in the lab. But the genetic basis of building is not the only, or even the deepest, mystery surrounding the animal kingdom's architects. There is also the issue of why nests vary so greatly across different species and how to explain their particular and often peculiar shapes.

Towering Termites
The nests of Peromyscus mice and most mammals are fairly simple; they do not vary immensely from region to region and species to species—an extra tunnel here, a larger chamber there. Even among birds, real variety in nest structure is the exception rather than the rule. Most bird nests are simple cups, bowls or pouches, differing in the subtleties of their shape and components rather than in more fundamental ways. The true animal masters of architecture are social insects. The beehive, the wasp nest, the ant mound, the termite hill: each of these varies from one species to the next more than the bodies of the insects themselves do. Termite workers nearly always look the same—flaccid abdomens connected to round heads and mandibles—but their nests can look like Rorschach forms, skyscrapers eight meters tall, domes, pyramids and even crumbly balls suspended in trees.

It would be easy to discount this diversity as accidental—the manifestation of a clumsy collective of unknowing beasts. Yet in many cases that have been studied, the features of nests are consistent from one structure to the next within a species. This consistency extends to parts of the nest that appear to have no function, such as vacant chambers. But termites build these puzzling features into their nests over and over again. In recent years scientists have started to uncover the purpose of such chambers.

This architectural puzzle is especially apparent in the nests of Macrotermes bellicosus termites, which farm and harvest Termitomyces fungi inside their homes. Surrounding these gardens and their millions of attending termites are central towers with pointy, sealed tops. Around these towers sit well-used chambers in which workers, and even the queen, live, along with an outer row of unused chambers. The creatures coat the unused chambers with a hard but porous surface that allows air, but not predators, to pass through.

Judith Korb of the University of Regensburg in Germany has been particularly interested in these features of giant Macrotermes mounds. With help from temperature sensors, collaborators and a whole lot of digging, Korb has discovered that the seemingly unusual architectural features of termite nests work like a giant mud lung. During the day the heated air, full of carbon dioxide exhaled by the termites, rises into the center of the nest. There, in the thinnest part of the mound, the hot air and CO2 diffuse upward. If they did not, the insects would suffocate in their own exhalation. As night comes, cooler, oxygen-rich air diffuses back into the bottom of the nest, in through the empty outer chambers. As it does, it pushes CO2-laden air out. This big mud lung is adapted to the climate in which the Macrotermes termites live. Far from being accidental and useless, the nest's empty chambers allow the termite collective to breathe.

In addition to microclimate control, nests also shield their builders from enemies. Termite nests are as thick as they are because of the threats posed by aardvarks, anteaters, armadillos, echidnas and a small army of other organisms that specialize in eating termites. To protect its young from parasites, a newly identified species known as the bone-house wasp blockades its nest with pungent piles of fearsome ant corpses. Then, of course, there is the option of an escape tunnel. The oldfield mouse lives in the southeastern U.S., where snakes are abundant and diverse. Its escape hatch most likely is an adaptation in response to such serpents. Some tropical ants have recently been shown to keep a pebble near their nest entrance. When army ants approach, they close the nest with their pebble. Other ants defend against army ants by having soldiers with heads just wide enough to plug the entrance. Some birds defend their nests through camouflage, creating inconspicuous nests, such as those of cream-colored coursers, which look like little more than pebbles in the desert sand.

Perhaps the greatest challenge for nature's builders is one that scientists have only begun to consider: excluding deadly organisms too small to see, such as bacteria and microscopic fungi. In the past few years researchers have discovered that some termites build their nests out of their own feces, often mixed with other materials. In these fecal bricks, some termites plant a garden of Actinobacteria, which helps to battle deadly fungi by producing antifungal compounds. Leafcutter ants cultivate similarly defensive bacteria on their bodies.

Communal Construction
Once we understand the environmental conditions and threats that have favored a particular nest type and the genes associated with that type, we will still need to figure out how those genes guide an animal through the nest-building process. In the case of social insects, it is tempting to think that the colony merely obeys a ruler—some fat-bodied queen with a scheme. But there is no master plan, just the unconscious actions of many individuals following simple rules that, when acted out in concert, can produce the enormous nests of termites, the cavernous lairs of ants and even the intricate honeycombs of bees.

Over the past 15 years scientists have developed increasingly sophisticated mathematical models that mimic how such simple rules culminate in the construction of termite homes. The models assume that the building blocks the termites use have a pheromone in them that triggers additional building but eventually wears off. One worker puts down a block, and another, tempted by the first block's odor, follows suit. The process continues until two curving walls come together to form a roof. The act of building walls and roofs was easy to simulate. But what about the precise arrangement of those walls to form tunnels and rooms?

Here, too, simple rules seem to be at the heart of the complexity, although the story continues to emerge. Regarding, for example, the royal chamber—the oval room that surrounds the queen termite—it appears that the queen emits a pheromone that prevents workers from building walls close around her. The workers, as a result, build a wall a consistent distance from the queen. Rather than imagining they have discovered exactly how these termites and wasps build their homes, scientists believe they have gleaned the minimum number of rules necessary to produce something as sophisticated as a nest. The answer is very few—a handful encoded in the insects' genes and tiny brains.

In contrast to the diverse, genetically encoded, often cooperatively constructed nests of rodents and social insects, the nests of wild primates are humble. Chimpanzees and gorillas break off leaves to make beds; one of my colleagues has slept in these beds and describes them as “comfortable” but only relative to their absence. Our ancestors are unlikely to have been very different until, at some point, our kind began to build in earnest. Using language to coordinate their efforts, our ancestors built homes out of what was at hand: sticks, mud, grass and leaves. No genes encoded the precise designs of these shelters. Look at images of indigenous houses around the world, and you will see that, to a large extent, form follows function and necessity. In cold regions, walls are made thicker. In warm regions, walls are not built at all. You will see traditional houses that mimic termite nests, ant tunnels and even, in the cold, the sod thatch of bumblebees.

The more time we invested in considering how to build houses, the more roles houses took on: they have become status symbols, artworks and even markers of culture. Houses in some new Arizona subdivisions now look very similar to those in New York subdivisions because we are conditioned by society to desire the same “good life”—the same house and white picket fence—regardless of where we live, regardless of climate, predators, pathogens or anything else. We have disconnected our architecture from some of the imperatives of the wild.

Recently, though, a different approach to architecture has emerged, a counterbalance to the trend of individually designing each room, each support, each door and garden. The designs of animals, as we now know, emerge from genes that encode simple rules. If termites can use simple rules to produce empires, we, too, might do the same. Some architects are now trying. Scaling up the simple rules used by social insects to human-sized cities requires tremendous computing power, but such power is increasingly a reality. The final challenge is knowing which simple decisions to mimic—in what situations it is best to behave like a termite, an ant or a bee. We are as close to the answers as we have ever been. Yet to watch empires of mud and spit rise out of the ground one mouthful at a time is to realize that the earth's most ancient architectural techniques remain very much a secret.