Scientists have discovered how the wiring of bees' brains helps them navigate the most direct route back to their hive.

Researchers from the University of Edinburgh found that neurons which transmit information to bees' brains remember changes in direction and distance covered, allowing the insects to return home in a straight line.

Bees use their vision to navigate, but little was known about what happens to their brains - which are smaller than a grain of rice - when they set off on their return journey.

Scientists discovered neurons that detect speed and direction in the part of the insect's brain called the central complex. This region also controls the navigation system used by ants, humans and others.

The cells are used to add up all elements of the outbound journey, creating a memory that bees use to fly home by the most direct route.

Professor Barbara Webb, of the University of Edinburgh's School of Informatics, who was involved in the study, said: "The most exciting part of this research was when computer modelling of the 'spaghetti' of connections between nerve cells revealed the elegant principle by which bees keep track of their position and steer back home."

The study involved a team of scientists who studied the brains of nocturnal rain forest bees.

They monitored nerve function by attaching tiny electrodes to bees' heads as the insects were shown virtual reality simulations of what they see when flying forward or rotating.

Their results, together with microscope studies of how the nerve cells are connected, were used to develop a detailed computer model of a bee's brain. The model was then tested on a simulated bee and a robot.

Professor Webb added: "Understanding such a complex behaviour at the level of single neurons is an important step forward for the science of brain function."

Scientists hope the findings could lead to the development of new algorithms for navigation in autonomous robots that do not require GPS or expensive computer systems.

The study, published in the journal Current Biology, was a collaboration with the University of Lund, Sweden and was funded by Swedish, UK and European research councils.