It has been widely recognized that the pH environment influences the nanobubble dynamics and hydroxide ions adsorbed on the surface may be responsible for the long-term survival of the nanobubbles. However, understanding the distribution of hydronium and hydroxide ions in the vicinity of a bulk nanobubble surface at a microscopic scale and the consequent impact of these ions on the nanobubble behavior remains a challenging endeavor. In this study, we carried out deep potential molecular dynamics simulations to explore the behavior of a nitrogen nanobubble under neutral, acidic, and alkaline conditions and the inherent mechanism, and we also conducted a theoretical thermodynamic and dynamic analysis to address constraints related to simulation duration. Our simulations and theoretical analyses demonstrate a trend of nanobubble dissolution similar to that observed experimentally, emphasizing the limited dissolution of bulk nanobubbles in alkaline conditions, where hydroxide ions tend to reside slightly farther from the nanobubble surface than hydronium ions, forming more stable hydrogen bond networks that shield the nanobubble from dissolution. In acidic conditions, the hydronium ions preferentially accumulating at the nanobubble surface in an orderly manner drive nanobubble dissolution to increase the entropy of the system, and the dissolved nitrogen molecules further strengthen the hydrogen bond networks of systems by providing a hydrophobic environment for hydronium ions, suggesting both entropy and enthalpy effects contribute to the instability of nanobubbles under acidic conditions. These results offer fresh insights into the double-layer distribution of hydroxide and hydronium near the nitrogen-water interface that influences the dynamic behavior of bulk nanobubbles.