The core function of all brains is to compute the current state of the world, compare it to the desired state of the world and select motor programs that drive behavior minimising any mismatch. The circuits underlying these functions are the key to understand brains in general, but so far they are completely unknown. Three problems have hindered progress: 1) The animal's desired state of the world is rarely known. 2) Most studies in simple models have focused on sensory driven, reflex-like processes, and not considered self-initiated behavior. 3) The circuits underlying complex behaviours in vertebrates are widely distributed, containing millions of neurons. With this proposal I aim at overcoming these problems using insects, whose tiny brains solve the same basic problems as our brains but with 100,000 times fewer cells. Moreover, the central complex, a single conserved brain region consisting of only a few thousand neurons, is crucial for sensory integration, motor control and state-dependent modulation, essentially being a 'brain in the brain'. To simplify the problem further I will focus on navigation behavior. Here, the desired and actual states of the world are equal to the desired and current headings of the animal, with mismatches resulting in compensatory steering. I have previously shown how the central complex encodes the animal's current heading. Now I will use behavioural training to generate animals with highly defined desired headings, and correlate neural activity with the animal's 'intentions' and actions - at the level of identified neurons. To establish the involved conserved core circuitry valid across insects I will compare species with distinct lifestyles. Secondly, I will reveal how these circuits have evolved to account for each species' unique ecology. The proposed work will provide a coherent framework to study key concepts of fundamental brain functions in unprecedented detail - using a single, conserved, but flexible neural circuit.