When insects go foraging, they zoom off from their nest in complex zig-zag paths. How do they manage to find their way back home? And how do they manage to do so along a straight path? These questions are explored in an exhibit at the Royal Society Summer Science Exhibition, currently taking place at the Southbank Centre in London.

"Despite their small size, ants and bees can teach us a lot about the cognitive building blocks of intelligence, and inspire the design of artificial brains for autonomous robots," says Andrew Philippides of the Centre for Computational Neuroscience and Robotics at the University of Sussex, who helped put together the exhibit. And it turns out that some simple maths sheds light on what goes on in insect's brains.

The main navigation mechanism, used by most animals, is called path integration and involves a little geometry. Look at the zig-zag path shown in blue in the diagram below. It's a sequence of arrows, known as vectors.

Moving along vector v 1 from the nest to point A is the same as moving one step to the right and two steps up, so we can represent the vector v 1 as a pair of numbers v 1 =(1,2). Similarly, we can write the vector v 2 from point A to point B as v 2 =(1,0). Now let's add the two vectors as follows:

v 3 =v 1 +v 2 =(1,2)+(1,0)=(1+1,2+0)=(2,2).

And now take the negative of the resulting vector v 3 :

–v 3 = (-2,-2).

The new vector -v 3 (taking two steps to the left and two steps down) points from point B straight back to the nest! The same is true if we add any number of successive vectors and then take the negative: we always get a vector pointing from our current location back to the nest. So to know our way back home, we don't even need to remember all the vectors we travelled along — we simply add the current one to the last total.

Biologists believe that insects have innate mechanisms to determine orientation and distance, which helps them represent each step in a foraging path by something akin to the vectors we have explored here. Neural processing enables them to add vectors as they go along, so they always know how to get back home quick. And insects are not the only ones — the technique explored here is sometimes called dead reckoning and it has been known to sailors for a long time.

With this technique small errors in measuring and adding up vectors can accumulate as the insect goes along. Insects then use other mechanisms to correct these errors, for example comparing what they see now to what they remember the world looking like from the nest. Scientists make extensive use of vector mathematics to model these other mechanisms too.

This article is based on the Maths Inside project, a collaboration of Plus and the Mathematics Promotion Unit (run by the London Mathematical Society and the Institute of Mathematics and its Applications), in conjunction with the How do insects find their way home? exhibit and the Royal Society. The Maths Inside project reveals the maths behind four specially chosen exhibits at the Royal Society Summer Science Exhibition. Click here to find out more about the project and to read articles accompanying other exhibits.