The molar mass of a gas can be derived from the ideal gas law, PV = nRT, by using the definition of molar mass to replace n, the number of moles.
Molar mass is defined as the mass of a substance occupied by exactly 6.022 * 10^23 of that respective gas' atoms (or molecules). Since we know that 6.022*10^23 represents Avogadro's number, and is the equivalent of 1 mole, we can describe molar mass as being equal to
M = m/n, where
m - the gas' mass in grams;
n - the number of moles of gas;
We can therefore write that n = m/M, which can be used in the ideal gas law equation to get the value of the gas' molar mass
PV = m/M * RT =>M = (m RT)/(PV), so
M = m * (RT)/(PV)
Here's an example of how this would look in a problem:
An unknown gas has a mass of 153 g and occupies 15.0 L at a temperature of 300.0 K and a pressure of 2.00 atm. What is its molar mass?
M = 153g * (0.082 (L * atm)/(K * mol) * 300.0K)/(2.00atm * 15.0L) = 125 "g/mol"