Opioids perform that trick by tinkering with chemical levels inside the brain. Typically, brain cells release a boost of a specific chemical, dopamine, when something rewarding or pleasant is happening. Opioids prompt the brain to release a lot of dopamine, so a person taking the drug might feel happy, at ease, or rewarded, even though something very painful is happening.
That same boost of reward can be terribly addictive, however, and people who take these drugs tend to need more and more of them to feel that same level of boost. As a result, opioids are terribly dangerous. Addicted people tend to take too much, and when they do, they suppress the urge to breathe. People can die due to this habit. In 2008 alone, according to NIDA, 14,800 overdose deaths were attributed to prescription opioids.