Opioids are a class of drugs that include both legal prescription pain relievers like morphine, oxycodone, and hydrocodone, as well as illegal drugs like heroin. They work by binding to opioid receptors in the brain and spinal cord to reduce pain perception.