Sensing trace amounts of 4-nitrophenol (4-NP) as a harmful substance to organisms even in small quantities is of great importance. The present study includes a sensitive and selective electrochemical sensor for detecting 4-NP in natural water samples using formamide-converted nitrogen-carbon materials (shortened to f-NC) as a new material for electrode modification. The structure and morphology of the f-NC were set apart by SEM, TEM, XRD, XPS, FTIR, Raman, and the electrochemical performance of the f-NC were set apart by CV, EIS and CC. We studied the electrochemical behaviour of 4-NP on the glassy carbon electrode modified with f-NC before and after pyrolysis treatment (denoted as f-NC1/GCE and f-NC2/GCE). In 0.2 M of H2SO4 solution, the f-NC2/GCE has an apparent electrocatalytic activity to reduce 4-NP. Under the optimal conditions, the reduction peak current of 4-NP varies linearly, with its concentration in the range of 0.2 to 100 mM, and the detection limit obtained as 0.02 mM (S/N = 3). In addition, the electrochemical sensor has high selectivity, and the stability is quite good. The preparation and application of the sensor to detect 4-NP in water samples produced satisfactory results, which provides a new method for the simple, sensitive and quantitative detection of 4-NP.