Although they can be small enough to waltz on your fingernail, spiders are capable of feats of breathtakingly beautiful and complex engineering.

That is, of course, their webs – structures that have fascinated and fired the human imagination for millennia. Now, we have the most detailed analysis yet of how they do so.

A team of scientists deployed night-vision cameras and artificial intelligence to study every position of all eight of a spider's legs during the construction of a web. The result is a model that can predict the stages of web building based on the posture of the spider's legs.

This should be able to help scientists figure out what's going on in their tiny spider brains as they work away, spinning in the dark.

uloborus diversus hackled orb weaver on webUloborus diversus on one of its intricate webs. (Michael Schmidt/Flickr/CC BY-NC-SA 2.0)

"I first got interested in this topic while I was out birding with my son. After seeing a spectacular web I thought, 'if you went to a zoo and saw a chimpanzee building this you'd think that's one amazing and impressive chimpanzee.' Well this is even more amazing because a spider's brain is so tiny and I was frustrated that we didn't know more about how this remarkable behavior occurs," says behavioral biologist Andrew Gordus of Johns Hopkins University.

"Now we've defined the entire choreography for web building, which has never been done for any animal architecture at this fine of a resolution."

Although no other animal builds in quite the same way humans do, we are not unique in our ability to construct. Other primates build nests, as do many birds. Some crabs build chimneys, and some caddisfly larvae construct protective cases to live in. But none of these are as intricate, varied or beautiful as the webs of spiders.

At the heart of the attempt to build a library of spider web-building movements is Uloborus diversus, a member of a family of spiders known as hackled orb weavers. These common non-venomous and insectivorous spiders, just a few millimeters across in size, can be found in the US and Mexico. As orb-weaving spiders do, they build intricate webs every night to ensnare their prey.

Six spiders were enlisted for the recording process. Each night, using infrared cameras and lights, the researchers recorded these spiders as they built their webs, using limb-tracking neural networks to monitor 26 points on each spider's body: the base, femur, and tibia of every leg, as well as the front- and rear-most points of the body.

"Even if you video record it, that's a lot of legs to track, over a long time, across many individuals," said neurophysiologist Abel Corver of Johns Hopkins University.

"It's just too much to go through every frame and annotate the leg points by hand so we trained machine vision software to detect the posture of the spider, frame by frame, so we could document everything the legs do to build an entire web."

In this way, the researchers recorded the hours-long construction of 21 webs, and each arachnid body movement that went into said construction.

This is the first step towards recording how the spiders' tiny brains can support the complexity of web building, and it paid off. The researchers found that each spider's web-making process involved the same motions and motor skills, to the point that the part of the web under construction could be predicted just from the position of a leg.

"Even if the final structure is a little different, the rules they use to build the web are the same," Gordus says. "They're all using the same rules, which confirms the rules are encoded in their brains. Now we want to know how those rules are encoded at the level of neurons."

This is going to be the subject of the next phase of research. The team plans to put the spiders under the influence of mind-altering chemicals to determine which parts of the brain are engaged in the web-building process, and how. (Drugs, including caffeine, have been given to spiders in studies before, so we have some indication that this can produce an effect on their web-building ability.)

"Pharmaceutical delivery and subsequent behavioral analysis would be needed to infer how drug-induced changes in behavior lead to altered web architecture. We hope to combine both approaches in future work," the researchers wrote in their paper.

"The behavioral analyses performed here provide a useful set of tools to probe the underlying structure of this behavior further and, ultimately, how this structure is encoded in the brain."

The research has been published in Current Biology.