Since noxious stimulation usually leads to the perception of pain, pain has traditionally been considered sensory nociception. But its variability and sensitivity to a broad array of cognitive and motivational factors have meant it is commonly viewed as inherently imprecise and intangibly subjective. However, the core function of pain is motivational-to direct both short-and long-term behavior away from harm. Here, we illustrate that a reinforcement learning model of pain offers a mechanistic understanding of how the brain supports this, illustrating the underlying computational architecture of the pain system. Importantly, it explains why pain is tuned by multiple factors and necessarily supported by a distributed network of brain regions, recasting pain as a precise and objectifiable control signal.Despite the advent of brain imaging, a clear picture of how pain is processed in the brain has been much harder to unravel than anticipated, being beset by three problems. First, pain is associated with robust responses in multiple and diverse brain regions, most of which are not specific to pain (at least on a macroscopic scale), and so it has been hard to ''pin down'' the pain system to any specific brain region. Second, pain is an inherently private percept, but an individual's self-reports of pain can vary widely from moment to moment, and it has remained unclear whether this fluctuation represents irreducible noise and subjectivity or a precise tuning of pain based on hidden factors. Third, pain is exquisitely sensitive to a broad range of emotional, environmental, and cognitive factors-a phenomenon called endogenous modulation. Although this has led to an appreciation that pain is more than a simple readout of nociceptive input, it has not led to any satisfactory unified explanation as to what pain really is. This has left the view that pain is simply a highly variable and malleable representation of assumed actual or potential tissue damage.In this review, we propose a model of pain that centralizes its role as a learning and control signal and argue that this can solve these problems. We begin with a perspective of how theories of pain have evolved over recent decades, and how insights have emerged that have moved thinking beyond purely sensory accounts of pain. We then argue that current accounts still don't fully capture how pain controls behavior to minimize harm, which is its primary function. Importantly, although this is often achieved by immediate nocifensive responses, a substantial part of this comes from learning-allowing an animal to mitigate or avoid predictable harm long into the future. The foundations of a learning account of pain are rooted in psychological models of animal learning, and we describe how these can be developed in computational terms to provide a mechanistic model of the architecture of the pain system. Critically, we argue that this requires pain to be shaped by a set of factors to optimize its role as a learning and control signal and review evidence that suggests that a great...