The neural bases of the different processes involved in task switching remain poorly identified. Whether distinct brain regions are involved according to the overall structure of the task sequence and the predictability of task timing during task switching is unknown. To address this question, we used functional magnetic resonance imaging and a 2 x 2 factorial design varying timing (fixed/random) and task order (predictable/unpredictable). We hypothesized that predictable task order should activate brain regions involved in long-term memory retrieval because retrieving which task has to be performed constitutes the essential part of what subjects can do to prepare before stimulus presentation. When examining the "pure" main effects of task order/timing predictability/ unpredictability, we found that anticipating task order activated the right hippocampus, the anterior medial prefrontal cortex, and the posterior cingulate cortex, while anticipating task onset timing activated the left middle and superior frontal gyrus. Furthermore, task order unpredictability activated the intraparietal cortex bilaterally while random relative to fixed timing activated the right cerebellum. Interactions between task order and timing were found in a network, which included the left frontopolar cortex and the lateral prefrontal cortex bilaterally. Specifically, the left frontopolar cortex was more activated when both timing and task order were predictable, while the lateral prefrontal cortices were more activated when both task order and timing were unpredictable. These results indicate a hierarchic organization of the prefrontal cortex along a posterioanterior axis as the task becomes more endogenously guided. Finally, we found no evidence for specific brain regions involved in task switching because a bilateral prefronto-parietal network, which was activated in task switching relative to performing each task separately, was no longer activated relative to a control condition, which required subjects to maintain two tasks in memory without switching between them.