Imagine constructing a building with no blueprints or architects, and no inkling of what the finished edifice should look like. It sounds like a recipe for disaster, and yet that’s what ants and termites do all the time—and the results speak for themselves. They can build huge underground metropolises full of interconnected chambers and galleries, or skyscraping mounds that have their own in-built air-conditioning, and all without overarching plans or large brains. How do they do it?

It’s an old mystery, and one that Guy Theraulaz from Paul Sabatier University is starting to answer. By studying the common black garden ant, he has shown that these insects write their architectural plans into the very walls of their buildings, during the construction process.

The black garden ant made a good subject because, in addition to digging underground chambers that are hard to see and study, it also builds small mounds by piling soil particles together.

To understand how the ants build these nests, Theraulaz’s team placed 500 of them in a large Petri dish covered with a thin layer of soil. Within a few hours, the ants started building. They’d pick up a small bit of soil and shape it into a pellet. They then piled these into regularly spaced pillars, around ten millimetres apart. Once the pillars reached a certain height, the ants added soil to their sides, creating caps, arches, and eventually closed roofs.

To build the roofs, the ants seem to use their own bodies as gauges. Once the pillars reach four millimetres in height—the average length of an ant worker—the ants stop building upwards and start extending laterally.

Building the pillars is a bit more complicated. The team found that ants were more likely to place their pellets at places where previous pellets had already been placed, and less likely to pick up pellets from those same spots. That’s probably because they impregnate their pellets with some kind of pheromone, which attracts other workers. That’s why they’ll gather around a pillar that other ants had constructed, but not around an equivalent one that Theraulaz’s team made using fresh soil.

Termites do something similar: They incorporate a “cement pheromone” into their nest materials, prompting other workers to add more pellets onto existing constructions. And ants use an equivalent trick when foraging, laying down trail pheromones that lead their sisters towards sources of food. These are all examples of stigmergy—a concept coined in the 1950s, in which animals coordinate their actions by dotting their environments with substances or cues that influence the behaviour of their peers. “It’s a way of indirectly controlling the collective actions of a group of insects through local information,” says Theraulaz.

His team haven’t figured out exactly what the ant’s cement pheromone is yet, but they managed to study it regardless. Anais Khuong and Jacques Gautrais built a computer simulation in which virtual ants pick up and lay down virtual particles, which are daubed with virtual pheromones. If the team set these pheromones to last for 800 to 1,200 seconds before diffusing away, their simulations accurately mimicked the structure of the real nests and the densities of actual pillars.

Note that none of the virtual ants had any idea about what they were trying to build. They were operating according to the simplest of building rules, and that was enough to create a realistic set of basic features, like pillars and roofs.