Neural responses and behavior are influenced by internal brain states, such as arousal, vigilance, or task context. Ongoing variations of these internal states affect global patterns of neural activity, giving rise to apparent variability of neural responses to sensory stimuli, from trial-to-trial and across time within single trials. Demultiplexing these endogenously generated and externally driven signals proved difficult with traditional techniques based on trial-averaged responses of single neurons, which dismiss neural variability as noise. In this talk, I will describe my recent work leveraging multi-electrode neural activity recordings and computational models to uncover how internal brain states interact with perception and goal-directed behavior. I will show that ensemble neural activity within single columns of the primate visual cortex spontaneously fluctuates between phases of vigorous (On) and faint (Off) spiking. These endogenous On-Off dynamics, which reflect global changes in arousal, are also modulated at a local scale during spatial attention and predict behavioral performance. I will also demonstrate that these On-Off dynamics provide a single unifying mechanism that explains general features of correlated variability classically observed in cortical responses (e.g., changes in neural correlations during attention). I will conclude by sketching out a roadmap for developing a general theory that will allow us to discover dynamic computations from large-scale neural recordings and to link these computations to behavior.