Precise management of the inverse correlation between the total porosity and compressive strength is crucial for the progress of foaming glass-ceramics (FGCs). To deeply understand this relationship, we investigated the atomic-level transformations of five CO2-foaming FGC samples using molecular dynamics simulation. The short-range and intermediate-range structures of the FGCs with varying total porosities (36.68%, 66.28%, 66.96%, 72.21%, and 79.88%) in the system were elucidated. Na cations were observed to exhibit a strong interaction with CO2, accumulating at the surface of the pore wall and influencing the oxygen species. Therefore, the change in the atomic structure of the matrix was accompanied by an increase in the total porosity with an increasing CO2 content. Specifically, as the total porosity increased, the bridging oxygen content within the FGCs rose accordingly. However, once the total porosity exceeded 66.96%, the bridging oxygen content began to decline. This observation was significant considering the role of the bridging oxygen content in forming a continuous cross-linked network of chemical bonds, which contributed to the enhanced mechanical strength. Consequently, the influence of the total porosity on the oxygen species resulted in a two-stage reduction in the compressive strength. This study offers valuable insights for the development of high-strength lightweight FGCs.