A ubiquitous feature of the vertebrate anatomy is the segregation of the brain into white and gray matter. Assuming that evolution maximized brain functionality, what is the reason for such segregation? To answer this question, we posit that brain functionality requires high interconnectivity and short conduction delays. Based on this assumption we searched for the optimal brain architecture by comparing different candidate designs. We found that the optimal design depends on the number of neurons, interneuronal connectivity, and axon diameter. In particular, the requirement to connect neurons with many fast axons drives the segregation of the brain into white and gray matter. These results provide a possible explanation for the structure of various regions of the vertebrate brain, such as the mammalian neocortex and neostriatum, the avian telencephalon, and the spinal cord.