Recent studies have shown that many of the components needed to transmit electrical signals, and to release and detect chemical signals, are found in single-celled organisms known as choanoflagellates. That is significant because ancient choanoflagellates are thought to have given rise to animals around 850 million years ago.
So almost from the start, the cells within early animals had the potential to communicate with each other using electrical pulses and chemical signals. From there, it was not a big leap for some cells to become specialised for carrying messages.
These nerve cells evolved long, wire-like extensions - axons - for carrying electrical signals over long distances. They still pass signals on to other cells by releasing chemicals such as glutamate, but they do so where they meet them, at synapses. That means the chemicals only have to diffuse across a tiny gap, greatly speeding things up. And so, very early on, the nervous system was born.
The first neurons were probably connected in a diffuse network across the body (see diagram). This kind of structure, known as a nerve net, can still be seen in the quivering bodies of jellyfish and sea anemones.
But in other animals, groups of neurons began to appear - a central nervous system. This allowed information to be processed rather than merely relayed, enabling animals to move and respond to the environment in ever more sophisticated ways. The most specialised groups of neurons - the first brain-like structure - developed near the mouth and primitive eyes.
Our view of this momentous event is hazy. According to many biologists, it happened in a worm-like creature known as the urbilaterian (see diagram), the ancestor of most living animals including vertebrates, molluscs and insects. Strangely, though, some of its descendants, such as the acorn worm, lack this neuronal hub.
It is possible the urbilaterian never had a brain, and that it later evolved many times independently. Or it could be that the ancestors of the acorn worm had a primitive brain and lost it - which suggests the costs of building brains sometimes outweigh the benefits.
Either way, a central, brain-like structure was present in the ancestors of the vertebrates. These primitive, fish-like creatures probably resembled the living lancelet, a jawless filter-feeder. The brain of the lancelet barely stands out from the rest of the spinal cord, but specialised regions are apparent: the hindbrain controls its swimming movements, for instance, while the forebrain is involved in vision. "They are to vertebrates what a small country church is to Notre Dame cathedral - the basic architecture is there though they lack a lot of the complexity," says Linda Holland at the University of California, San Diego.
Some of these fish-like filter feeders took to attaching themselves to rocks. The swimming larvae of sea squirts have a simple brain but once they settle down on a rock it degenerates and is absorbed into the body.
We would not be here, of course, if our ancestors had not kept swimming. And around 500 million years ago, things went wrong when one of them was reproducing, resulting in its entire genome getting duplicated. In fact, this happened not just once but twice.
These accidents paved the way for the evolution of more complex brains by providing plenty of spare genes that could evolve in different directions and take on new roles. "It's like the time your parents bought you the biggest Lego kit - with loads of different components to use in different combinations," says Grant. Among many other things, it enabled different brain regions to express different types of neurotransmitter, which in turn allowed more innovative behaviours to emerge.
As early fish struggled to find food and mates, and dodge predators, many of the core structures still found in our brains evolved: the optic tectum, involved in tracking moving objects with the eyes; the amygdala, which helps us to respond to fearful situations; parts of the limbic system, which gives us our feelings of reward and helps to lay down memories; and the basal ganglia, which control patterns of movements (see diagram).