Developing an efficient adsorbent is of great significance to eliminate the adverse impacts on human and animals health caused by environmental concentration sulfamethoxazole (SMX). Various N-containing chemicals (ammonium chloride (NH4Cl), thiourea (CH4N2S), urea (CO(NH2)2), and melamine (C3H6N6)) were employed to activate sludge biochar (SBC) under hydrothermal condition. Afterward, the optimum hydrothermal N-doped SBC (NSBC-0.5) (C3H6N6 was confirmed as the perfect N-containing chemical) was further modified by ball milling to prepare BNSBC-0.5. The maximum adsorption capacity of BNSBC-0.5 for SMX calculated from Langmuir was 6.86 x 104 mu g/g. The physicochemical properties analysis, adsorption experiments, together with density functional theory (DFT) calculation confirmed that the process of SMX adsorption onto BNSBC-0.5 was dominantly by Lewis acid-base, pi-pi conjugation, pore filling and electrostatic interactions. The multiple adsorption mechanism guaranteed the high anti-interference of BNSBC-0.5 to inorganic salts/strength and organic matter concentrations range and enabled it to be a promising adsorbent for efficiently eliminating SMX in various actual waters (Yangtze River water (88.5 %), lake water (89.3 %), running water (89.2 %), pure water (92.7 %), and deionized water (92.5 %)). The regenerated (via NaOH desorption) BNSBC-0.5 was capable of sustainably and effectively adsorbing SMX in recycles. Additionally, BNSBC-0.5 exhibited the satisfactory environmental safety in view of the low leaching levels of total nitrogen (TN) over a board pH range. This work synthesized a prospective adsorbent for SMX elimination, also the harmless disposal and waste utilization of sludge were accomplished.