Dimethyl sulfate (DMS) is widely used in manufacturing process but because of its genotoxicity nature, it should be monitored at trace levels (1μg/mL). It is complicated and difficult to quantify DMS in cephalosporin with traditional method. Herein, a method for quantifying residual DMS in cephalosporin was developed, without complex sample preprocessing, no need for a large amount of solvent, employing headspace solid-phase microextraction (SPME) and gas chromatography-mass spectrometry (GC-MS). Compared with polydimethylsiloxane (PDMS)/divinylbenzene and polyacrylate fibers, PDMS was more suitable for absorbing DMS. The research showed that the PDMS fiber should be changed after 50 adsorption-desorption cycles. Linear regression analysis of the calibration curve demonstrated a robust linear relationship, with R2 of 0.999, across a concentration range of 0.25 to 4.0μg/mL. The method underwent rigorous validation for specificity, linearity, precision and accuracy. This method was proven effective in measuring DMS in complex matrices. The limits of detection and quantification for this method is 0.05 and 0.25μg/mL, respectively, which has room for improvement.