Much of human behavior is characterized by the extraordinary ability to quickly reconfigure our mind, and switch between different tasks, often referred to as cognitive flexibility. While most psychologists agree on the kind of behaviors that fall under the term cognitive flexibility, we have only a poor understanding on what drives cognitive flexibility. When defining cognitive flexibility, its putative underlying processes are often distinguished from other functions of the brain by opposing them to low-level learning. In contrast, this project starts from the idea that cognitive flexibility is grounded in reinforcement learning and associative learning, and thus sensitive to the same rules that low-level learned behavior is subject to. Therefore, the first two aims of this project will be to demonstrate that the processes behind cognitive flexibility can be conditioned by reward and controlled by the context. This approach breaks with a traditional view on cognitive flexibility as originating from a vague, independent supervisory system. Instead, it allows us to get a grip on cognitive flexibility, and study its neural mechanisms more closely. To this end, a third aim will be to test the counterintuitive hypothesis that increased neural variability (or "noise") in control regions of the brain is what allows for cognitive flexibility. Finally, I will apply this fundamentally different way of understanding cognitive flexibility to the clinical domain. Autism spectrum disorder (ASD) has been linked to deficits in cognitive flexibility, but studies have shown mixed results. Accordingly, a fourth aim will be to further the understanding of the assumed deficits in cognitive flexibility related to ASD. Overall, this project intends to change the current way of thinking about cognitive flexibility, and cognitive control more generally, and to cause a paradigmatic shift in how we go about assessing its neural mechanisms and deficits in clinical conditions like ASD.