Neural responses are variable: the same external events usually trigger different patterns of neural activity. These activity fluctuations have been traditionally treated as noise. However, recent experiments have shown that they are not entirely random. For example, neural activity fluctuations are correlated with animal’s choices, and the strength of these fluctuations at different frequencies is modulated during spatial attention. Yet, it remains largely unknown whether neural activity fluctuations play a functional role and how these fluctuations are controlled in service of behavior. In my talk, I will address both these questions. First, I will show that choice-correlated activity fluctuations play a critical role in reward-dependent learning. As an example, I consider categorization, an essential cognitive ability to group stimuli into discrete classes, and construct a biophysical model capable of learning categorization through reward-dependent plasticity. In the model, stable category representations develop in neurons intermediate to sensory and decision layers only if they exhibit choice-correlated activity fluctuations arising from plastic top-down projections. Specific model predictions are confirmed by analyses of recordings from monkey parietal cortex. Second, I will present an analysis of ensemble neural activity recorded with linear electrode arrays across layers in monkey visual cortex during a demanding attention task. This ensemble neural activity spontaneously transitions between episodes of vigorous (On) and weak (Off) spiking synchronous throughout the cortical depth. Classic work in rodents relates such synchronous transitions to global changes of cortical state associated with arousal, as transitions are most prominent during slow-wave sleep and anesthesia, but are less conspicuous in awake animals. Using Hidden Markov Models, I will demonstrate that On-Off dynamics in primate cortex not only covary with arousal but are also modulated locally within a retinotopic map during spatial attention. Moreover, the instantaneous cortical state predicts animals’ behavioral responses, suggesting that local changes in the On-Off dynamics have direct behavioral consequences. These results elucidate the dynamics of neural activity fluctuations and demonstrate that cortical state is locally modulated to serve behavioral goals, challenging the traditional view of cortical state as a mere reflection of arousal.