For a gas, the density is approximately proportional to the number of gas molecules within a unit volume. So if we compress a volume of gas, which means the volume becomes smaller and thus the space between the molecules is reduced, the gas density increases. An expansion is the opposite of a compression.