Cognitive and behavioral flexibility necessitate mental and behavioral changes in response to changing environmental demands. Cognitive flexibility, or the mental ability to change from one thought to another, supports positive life outcomes. Individuals diagnosed with autism spectrum disorder (ASD) often face challenges with cognitive flexibility as exhibited by a core symptom of restricted and repetitive interests and behaviors (RRBs) and having poor adaptive behavior skills. ASD is rising each year, with one in 36 children diagnosed annually. Early diagnosis and treatment are critical for improving life outcomes. This makes it even more important to investigate the neural underpinnings of cognitive flexibility during early stages of development and across the lifespan to improve treatments and interventions. This dissertation seeks to understand the neural mechanisms underlying healthy cognitive flexibility development and the cognitive inflexibility observed in ASD. Chapter 1 includes an introduction to the research involved in the following chapters, and provides a review of cognitive flexibility and its neural correlates in typical development and in ASD. Chapter 2 includes a study exploring brain dynamics and cognitive flexibility across the lifespan in a neurotypical population. Using a co-activation pattern analysis method to investigate brain dynamics, brain networks including the salience (SN), default mode (DMN), and central executive networks (CEN) underlie changes in cognitive flexibility across the lifespan. Chapter 3 then explores the neural correlates of shifting in children with and without autism during a task and resting state fMRI. Results of this study further revealed brain dynamics among the SN, DMN and CEN were involved in shifting abilities and abnormalities in these dynamics may underlie differences observed in children with ASD. Chapter 4 then examines early brain dynamics in toddlers with and without ASD and their relationship with flexible behaviors. Findings reveal differences in brain dynamics among the SN, DMN, and CEN in toddlers later diagnosed with ASD compared with non-ASD toddlers. Additionally, brain dynamics among the SN, DMN, and CEN were associated with RRBs and real-world measures of flexible behaviors across all toddlers. Chapter 5 discusses the overall findings of this dissertation, limitations, and future directions. Overall, these data indicate the importance of investigating brain dynamics associated with cognitive flexibility across the lifespan. Further, it has potential implications for autism research, implying that brain network dynamics may be an early indicator for behavioral symptoms.