An automated headspace solid-phase microextraction coupled with gas chromatography-mass spectrometry (automated HS-SPME/GC-MS) for the determination of four N-nitrosamines N-nitroso-di-n-ethylamine, N-nitroso-di-n-propylamine, N-nitrosopiperidine and N-nitroso-di-n-butylamine in groundwater samples was developed. Response surface methodology was employed to optimize relevant extraction parameters including extraction time, sample pH, incubation temperature and salt addition. The optimal HS-SPME were 20 min of extraction time, sample pH of 7, incubation temperature of 65 degrees C and 30% (w/v) sodium chloride concentration. Under these conditions, good linearity for the analytes in the range from 0.1 to 100 mu g/L with correlation coefficient (R) from 0.975 to 0.992 was obtained. The limits of detection based on a signal-to-noise ratio of 3 were between 0.78 and 11.92 ng/L with corresponding relative standard deviations from 1.8 to 5.7% (n = 4). The average relative recoveries of the four N-nitrosamines from spiked different groundwater samples by 1 mu g/L and 20 mu g/L of each analyte (mean +/- standard deviation, n = 4) were 96.6 +/- 4.4 and 102.3 +/- 4.86 %, respectively. The method was applied to determine the N-nitrosamine in groundwater samples from different locations in Saudi Arabia. The average recoveries of spiked N-nitrosamines in different groundwater.