Postsynaptic integration is a complex function of passive membrane properties and nonlinear activation of voltage-gated channels. Some cortical neurons express many voltage-gated channels, with each displaying heterogeneous dendritic conductance gradients. This complexity has hindered the construction of experimentally based mechanistic models of cortical neurons. Here we show that it is possible to overcome this obstacle. We recorded the membrane potential from the soma and apical dendrite of layer 5 (L5) pyramidal neurons of the rat somatosensory cortex. A combined experimental and numerical parameter peeling procedure was implemented to optimize a detailed ionic mechanism for the generation and propagation of dendritic spikes in neocortical L5 pyramidal neurons. In the optimized model, the density of voltage-gated Ca(2+) channels decreased linearly from the soma, and leveled at the distal apical dendrite. The density of the small-conductance Ca(2+)-activated channel decreased along the apical dendrite, whereas the density of the large-conductance Ca(2+)-gated K(+) channel was uniform throughout the apical dendrite. The model predicted an ionic mechanism for the generation of a dendritic spike, the interaction of this spike with the backpropagating action potential, the mechanism responsible for the ability of the proximal apical dendrite to control the coupling between the axon and the dendrite, and the generation of NMDA spikes in the distal apical tuft. Moreover, in addition to faithfully predicting many experimental results recorded from the apical dendrite of L5 pyramidal neurons, the model validates a new methodology for mechanistic modeling of neurons in the CNS.