Some days I’m grumpy; other times, my head hurts or my feet or my arms do. Yet when I play the trumpet, my mood improves and the pain disappears. Why?

Alternative medicine — including music therapy — is full of pain-relief claims. Although some are simply too good to be true, the oddities of pain can explain why others hold up, as well as why my trumpet playing helps.

One thing we tend to believe about pain, but is wrong, is that it always stems from a single, fixable source. Another is that pain is communicated from that source to our brains by “pain nerves.” That’s so wrong it’s called “the naïve view” by neuroscientists.

In truth, pain is in our brain. Or as the author and University of California, San Diego, neuroscientist V. S. Ramachandran put it, “Pain is an opinion.” We feel it because of how our brain interprets input transmitted to it from all our senses, not necessarily because of the inherent properties of the input itself. There are no nerves dedicated to sensing and transmitting pain.

Anyone who has willed themselves to not feel a tickle as ticklish can appreciate the difference between stimulation and our perception of it. Pain can be experienced and relieved in phantom limbs.

Discomfort and swelling increase when people believe a painful hand or knee is larger. They decrease when it seems smaller, for example in a distorted image or based on virtual reality technology. Injections are less painful when we don’t watch them. Using our brains, we can exert some control over it.

On the one hand, this is not so surprising because every perception we have is the brain’s best guess at interpreting what is happening and what we should do about it. On the other hand, the feeling of pain is overwhelmingly palpable, corporeal — when you have pain, you have it somewhere. Nobody wants to hear, let alone believe, it’s made in our head.

“Many pain patients say, ‘I know my pain is real because I can feel it,’” said Lorimer Moseley, a clinical scientist and pain researcher at the University of South Australia. “All pain is real, no matter what is causing it. But also, all pain is made by the brain in response to the information available to it.”

According to his work and that of others, the degree of pain is not a reliable indicator of the severity of injury. And sometimes there is pain without any tissue damage at all.

An extreme example came from a 1995 report in the British Medical Journal. A builder jumped onto a nearly six-inch nail, which penetrated his boot’s sole, the tip visibly protruding from its top. To relieve his excruciating pain, doctors administered fentanyl and a sedative. But, when they removed the boot, the doctors discovered that the nail had passed between his toes, leaving his foot unharmed. There are many studies that find that the fear or catastrophizing of pain contributes to a greater feeling of pain.

When our brain decides to interpret a sensation as painful, it also sends a signal back to the body that intensifies that feeling. Nerve endings can chemically change in response to signals from the brain. Pain is more like a conversation between the brain and the body. And like verbal conversations, it can be heated or calm.

If something in the mind — fear — can make pain worse, can some other thoughts or mood make it better? Yes, to an extent.

For example, pain can be lessened when we feel safe. An early demonstration of this fact came from a study in JAMA in 1956. In it, wounded World War II soldiers were compared with civilians with similar injuries. Though 83 percent of the civilians requested narcotic pain killers, only 32 percent of the soldiers did. One interpretation of these results is that the soldiers felt safer just being off the battlefield, and that the relative sense of safety diminished their feeling of pain.

I experienced something akin to this when I had a kidney stone. Its pain was excruciating at home as well as on the way to the emergency department. But once there, I felt safer, and the pain began to subside even before I was given painkillers.

Love, like safety, can also ease pain. For example, a study published in Pain Medicine found that people who spend a greater portion of their day thinking about a romantic partner experience more pain reduction when viewing pictures of that partner than those less preoccupied with their partner. Other studies show that pain is reduced when partners hold hands.

Mr. Moseley has made the brain’s role in pain part of his life’s work. “The longer pain persists, the more sensitive the pain system becomes,” he said. “That’s what the nervous system does: It learns. Understanding this complex relationship, along with re-engaging the body, is the first step toward loosening pain’s grip.”

It’s not a cure all. We can’t think away all pain. For one, we don’t fully control our thoughts. Just as you can’t relax when told “to just relax,” you can’t become pain free just by telling yourself your brain is exacerbating your pain. Even the happiest, calmest optimists experience pain. For another, many people experiencing chronic pain are also experiencing other stressors that cause them to feel less safe and secure — feelings that exacerbate pain.

“Most people with chronic pain aren’t just a little stressed, they are a lot stressed,” said Paul Ingraham, who has made a career explaining the science of chronic pain and injury rehab. “They’re stressed by the pain itself and also by major life challenges and socioeconomic problems that no one could solve with anything less than years of effort and maybe a miracle or two.” Some stressors that exacerbate pain, as well as contribute to other health problems, are not so easily removed. For many, anxiety is an unavoidable feature of life, and it makes pain worse.

This points to the importance of addressing mental health alongside physical health. A recent systematic review of 202 clinical trials of nonpharmacological pain treatments found that those with evidence of effectiveness included approaches that addressed the mind, not just the body. According to the report, published by the Agency for Healthcare Research and Quality, these were “consistently associated with durable slight to moderate improvements in function and pain,” at least for some conditions.

Some stress reduction and promotion of feelings of safety can be achieved relatively easily. For example, deep breathing or listening to or playing music are relatively simple and inexpensive, and without harmful side effects. Others, like improving your social life or leaving a stressful job, take more work and can be more disruptive. Some might consider consulting professionals specializing in cognitive behavioral therapy and other mindfulness techniques aimed at addressing the brain-pain relationship.

Although all these can be of some help, they won’t eliminate all pain in all people, and in many cases they can only offer short-term relief. Perhaps because I find it calming, I feel much better after playing the trumpet, but I can count on pain’s return in some form another day.