SummaryPain after craniotomy remains a significant problem. The effect of morphine and tramadol patient‐controlled analgesia (PCA) on arterial carbon dioxide tension is unknown in patients having such surgery. Sixty craniotomy patients were randomly allocated to receive morphine PCA, tramadol PCA or codeine phosphate 60 mg intramuscularly. Baseline values of pain score (0–10), sedation and arterial carbon dioxide tension were recorded at the time of first analgesic administration and at 30 min, 1, 4, 8, 12, 18 and 24 h. Patient satisfaction was assessed at 24 h. There were no differences in arterial carbon dioxide tension or sedation between groups at any time, but in all three groups some patients had rises greater than 1 kPa. Morphine produced significantly better analgesia than tramadol at all time points (p < 0.005) and better analgesia than codeine at 4, 12 and 18 h. Patients were more satisfied with morphine than with codeine or tramadol (p < 0.001). Vomiting and retching occurred in 50% of patients with tramadol, compared with 20% with morphine and 29% with codeine.