This contribution discloses a new methodology for the preparation of N-doped carbon via the hydrothermal carbonization (HTC) of sewage sludge (SS). The aqueous phase served as the nitrogen source as it contained a large number of soluble proteins and cellulose, and rice husk served as the sugar source. The results showed that the lignin in the rice husk interfered with the hydrolysis of cellulose and hemicellulose. In comparison, the particle size of N-hydrochar produced from the co-HTC of cellulose and the aqueous phase of SS was uniform. Remarkably, the resulting carbon materials exhibited a maximum specific capacitance of 286.68 F g-1 at a current density of 1 A g-1 and also retained 76.74% of the capacitance at an ultrahigh current density of 20 A g-1. A maximum energy density of 39.81 W h kg-1 was obtained. Moreover, 97.55% of the initial capacitance of the assembled supercapacitor can be maintained after 10 000 cycles, exhibiting long cycling stability. The present method provides a new approach towards the preparation of sustainable functional carbon materials for energy applications from wastewater formed via HTC of SS. © The Royal Society of Chemistry.