How do we get to know the total mass of an atmosphere?
There is a simple$^*$ way to know the total mass of the atmosphere: measuring the pressure it exerts on the surface, which necessarily integrate all of the atmosphere above ground level.
If you take an atmospheric pressure of $1\cdot10^5$ Pa, it is equivalent to a force of $1\cdot10^5$ newton over one square meter. Multiply by the area of the planet in square meters, you get the total weight of the atmosphere: $1\cdot10^5 \times 5.1\cdot10^{14} = 5.1\cdot10^{19}$ N. Divide by the acceleration of gravity to convert this weight to a mass: $\frac{5.1\cdot10^{19}}{9.8} = 5.2\cdot10^{18}$ kg. There you go!
$^*$Well, I guess it is simple on Earth, but could be more challenging on other planets...