Opioids have a chemical structure similar to endorphins, a class of chemicals present in the brain. Endorphins are naturally manufactured in the brain to provide relief when the body experiences pain or stress.
Endorphins flood the synapses (the gaps between neurons) in the brain. They usually inhibit neurons from firing, and produce relief from pain and even euphoria. Endorphin levels go up when a person exercises, goes into labor, or has a high level of stress.
When someone takes an opioid drug it is rapidly converted to morphine in the brain. The morphine molecule binds to the endorphin-receptor sites on the neurons, and mimics the function of natural endorphins. Because the user can control how much of the false "endorphin" he or she receives, and consequently how much pleasure he or she receives, the likelihood of addiction is high.
After a period of use, most addicts no longer experience the euphoria. They continue to use the drugs only for relief of painful withdrawal symptoms.