Nitrogen (N) supports food production, but its excess causes water pollution. We lack understanding of the boundary of N for water quality while considering complex relationships between N inputs and instream N-concentrations. Our knowledge is limited in regional reduction targets to secure food production. Here we aim to derive a spatially-explicit boundary of N inputs to rivers for surface water quality using a bottom-up approach, and to explore ways to meet the derived N boundary while considering the associated impacts on both surface water quality and food production in China. We modified a multi-scale nutrient modelling system simulating around 6.5 Tg of N inputs to rivers that are allowed for whole of China in 2012. Maximum allowed N inputs to rivers are higher for intensive food production regions and lower for highly urbanized regions. When fertilizer and manure use is reduced, 45-76% of the streams could meet the N water quality threshold under different scenarios. A comparison of ‘water quality first’ and ‘food production first’ scenarios indicates that trade-offs between water quality and food production exist in 2-8% of the streams, which may put 7-28% of crop production at stake. Finally, we modelled the surface water quality of N for 2050 under climate change and explored the associated management scenarios. The results indicate that N pollution in surface water could be avoided in China while ensuring food security by spatial planning of livestock production combined with state-of-art N management technologies. Clearly, our insights could support region-specific policies for improving water quality.