Pain perception is influenced not only by sensory input from afferent neurons but also by cognitive factors such as prior expectations. It has been suggested that overly precise priors may be a key contributing factor to chronic pain states such as neuropathic pain. However, it remains an open question how overly precise priors in favor of pain might arise. Here, we first verify that a Bayesian approach can describe how statistical integration of prior expectations and sensory input results in pain phenomena such as placebo hypoalgesia, nocebo hyperalgesia, chronic pain, and spontaneous neuropathic pain. Our results indicate that the value of the prior, which is determined by generative model parameters, may be a key contributor to these phenomena. Next, we apply a hierarchical Bayesian approach to update the parameters of the generative model based on the difference between the predicted and the perceived pain, to reflect that people integrate prior experiences in their future expectations. In contrast with simpler approaches, this hierarchical model structure is able to show for placebo hypoalgesia and nocebo hyperalgesia how these phenomena can arise from prior experiences in the form of a classical conditioning procedure. We also demonstrate the phenomenon of offset analgesia, in which a disproportionally large pain decrease is obtained following a minor reduction in noxious stimulus intensity. Finally, we turn to simulations of neuropathic pain, where our hierarchical model corroborates that persistent non-neuropathic pain is a risk factor for developing neuropathic pain following denervation, and additionally offers an interesting prediction that complete absence of informative painful experiences could be a similar risk factor. Taken together, these results provide insight to how prior experiences may contribute to pain perception, in both experimental and neuropathic pain, which in turn might be informative for improving strategies of pain prevention and relief.