Diabetic patients frequently suffer from continuous pain that is poorly treated by currently available analgesics. We used mouse models of type 1 and type 2 diabetes to investigate a possible role for the hyperpolarization-activated cyclic nucleotide–gated 2 (HCN2) ion channels as drivers of diabetic pain. Blocking or genetically deleting HCN2 channels in small nociceptive neurons suppressed diabetes-associated mechanical allodynia and prevented neuronal activation of second-order neurons in the spinal cord in mice. In addition, we found that intracellular cyclic adenosine monophosphate (cAMP), a positive HCN2 modulator, is increased in somatosensory neurons in an animal model of painful diabetes. We propose that the increased intracellular cAMP drives diabetes-associated pain by facilitating HCN2 activation and consequently promoting repetitive firing in primary nociceptive nerve fibers. Our results suggest that HCN2 may be an analgesic target in the treatment of painful diabetic neuropathy.