Nitrous acid (HONO) plays a significant role in radical cycling and atmospheric oxidative chemistry. While the source and evolution of HONO in the Yangtze River Delta (YRD) region of China after 2018 remains largely unknown, this work monitored HONO and other air pollutants throughout 2019 at an urban site (Pudong, PD) and a suburban site (Qingpu, QP) in Shanghai. Episodes with high HONO mixing ratios but different PM2.5 levels, namely haze and clean episodes, were chosen for HONO budget analysis. Using an observation-based photochemical box model, relative importance of different sources and sinks of HONO were evaluated. Gas-phase reaction of NO with OH was found to be one of the most important daytime HONO formation sources, especially during the QPhaze period (accounting for 40.3 % of daytime HONO formation). In particular, heterogeneous conversion of NO2 on ground and aerosol surface was found to be the dominant source for nocturnal HONO. Photo-enhanced NO2 conversion on ground surface plays an important role in daytime HONO production (19.4 % in PDhaze vs. 27.6 % in PDclean, and 19.8 % in QPhaze vs. 25.9 % in QPclean). In addition, photo-enhanced NO2 conversion at the aerosol surface during haze episodes made more significant contributions to HONO formation compared to the clean periods (20.9 % in PDhaze vs. 17.1 % in PDclean, and 19.7 % in QPhaze vs. 11.2 % in QPclean). The role of multiphase reactions was found to be increasingly important in HONO generation with enhanced relative humidity (RH) during daytime. Significant unknown HONO source was further analyzed and found to be positively related with photolytic as well as multiphase pathways. Overall, our study sheds light on the budget of HONO in one of the biggest megacities in east China, which would help developing future mitigation strategies for urban HONO and atmospheric oxidation capacity.