For an ideal gas the equation of state can be written as 
where  is the ideal gas constant. The differential change of the chemical potential between two states of slightly different pressures but equal temperature (i.e., ) is given by
where ln p is the natural logarithm of p.
For real gases the equation of state will depart from the simpler one, and the result above derived for an ideal gas will only  be a good approximation provided that (a) the typical size of the molecule is negligible compared to the average distance between the individual molecules, and (b) 
the short range behavior of the inter-molecular potential can be neglected, i.e., when the molecules can be considered to rebound elastically off each other during molecular collisions. In other words, real gases behave like ideal gases at low pressures and high temperatures. At moderately high pressures, attractive interactions between molecules reduce the pressure compared to the ideal gas law; and at very  high pressures, the sizes of the molecules are no longer negligible and repulsive forces between molecules increases the pressure. At low temperatures, molecules are more likely to stick together instead of rebounding elastically.
The ideal gas law can still be used to describe the behavior of a real gas if the pressure is replaced by a fugacity , defined so that
and
That is, at low pressures  is the same as the pressure, so it has the same units as pressure. The ratio
is called the fugacity coefficient.
If a reference state is denoted by a zero superscript, then integrating the equation for the chemical potential gives
Note this can also be expressed with , a dimensionless quantity, called the activity.
Numerical example: Nitrogen gas (N) at 0 °C and a pressure of  atmospheres (atm) has a fugacity of  atm. This means that the molar Gibbs energy of real nitrogen at a pressure of 100 atm is equal to the molar Gibbs energy of nitrogen as an ideal gas at . The fugacity coefficient is .
The contribution of nonideality to the molar Gibbs energy of a real gas is equal to . For nitrogen at 100 atm, , which is less than the ideal value  because of intermolecular attractive forces. Finally, the activity is just  without units.