Density is defined as the mass of an object divided by its volume. 
Gas density
It gives a measure of the amount of matter there is per unit volume, how 'dense' something is. The density of a gas is the mass of a given volume of gas divided by its volume.
Gases have a much lower density than liquids or solids. Hydrogen is the least dense gas.
Density = mass/volume
units: g/cm^{3} or g cm^{3 }
Example: A block of wood was found to have a mass = 36 g. When fully immersed in water it displaced a volume of 126 cm^{3}. Calculate its density. Density = mass/volume Density = 36/126 = 0.286 gcm^{3} 
To find the density of a gas, the volume and the mass must be known. At STP both of these quantities are known, as 1 mole of any gas occupies 22700 cm^{3}. It is, therefore, a simple matter of dividing the molar mass by 22700 to obtain the density. The values produced, however, are very small and gas densities are instead often quoted in grams per litre for this very reason.
For example, hydrogen has a density at STP of 2/22700 = 8.8 x 10^{5} g/cm^{3}
Gas densities at STP (g/dm^{3})


Hydrogen  0.088 
Helium  0.176 
Oxygen  1.410 
Carbon dioxide  1.938 
Xenon  5.784 
Radon  9.780 
Relative density
Water has a density of about 1g per cm^{3} which can make it useful in calculations. Relative density (see relative measurements) is the density relative to the density of water, so if a substance has a relative density of 13.8 this means that it is 13.8 times as dense as water.
Water density = 1g per cm^{3}, so something with a relative density of 13.8 has a density = 13.8 g per cm^{3}.
Example: An evacuated sealed flask is weighed = m1 The flask is filled with an unknown gas and reweighed = m2 The flask is filled with water and the water poured into a measuring cylinder to find the volume = V The mass of the unknown gas = mass of the gas filled flask  mass of the empty flask = m2  m1 The density of the gas = mass of the gas/volume of the flask = (m2  m1)/V 
Once the density of a gas is known at a specific temperature, its mass can be obtained from the volume occupied.
Note: We are still referring to STP conditions; Under other temperature and pressure conditions the gas laws must be used.
Example: An unknown gas has a density of 1.79 x 10^{4} g/cm^{3} at STP, calculate its relative molecular mass. At STP 1 mole of gas occupies 22.7 dm^{3} = 22700 cm^{3} Therefore mass of 1 mol of the unknown gas at STP = 22700 x 1.79 x 10^{4} g = 4.06 g The relative molecular mass of unknown gas = 4.06 
Note: According to the gas laws, the volume of a gas is dependent on the temperature and so then is the density. As a gas increases in temperature it becomes less dense as the volume occupied by the same mass of gas increases. This is why hot air rises.
The hot air has a lower density than the surrounding colder air and is 'pushed up' by the colder air, in the same way as a piece of wood tends to be pushed up to the surface of water. The wood is less dense than water and therefore floats.