The stability and reliability of perovskite solar cells (PSCs) are severely affected by moisture. Therefore, it is very meaningful to study the barrier effect of gases with different compositions on moisture in a sealed environment. In this work, the stability of PSCs in a sealed environment filled with N-2, CO2 with an external environment of 45 degrees C and 85% RH was investigated. After 240 h treatment, the PCE of the PSCs in the CO2 sealed environment decayed to 71.1% of the initial value. The PCE of the PSCs in the N-2 sealed environment decayed to 51.8% of the initial value, while in the air environment as a control, the PCE decayed to 36.3% of the initial value. Through SEM, XRD film characterization and finite element simulation, it is found that both CO2 and N-2 can be used as shielding gases to inhibit moisture intrusion, thereby slowing down the decay rate of perovskite solar cells. And CO2 is more effective than N-2 in inhibiting moisture intrusion. On the one hand, CO2 molecules are larger than N-2 molecules. When tiny gaps appear in the sealed environment, N-2 molecules can escape, but CO2 cannot escape, which will lead to less moisture intrusion in the CO2 sealed environment. On the other hand, when there are large gaps in the sealed environment, both N-2 and CO2 can escape, because the diffusion coefficient of moisture in the N-2 sealed environment is larger, resulting in more moisture intrusion in the N-2 sealed environment.