Density is defined as the degree of compactness of the molecules of a substance. In other words, it is the measurement of how close the molecules of a substance are to each other.
For instance, a container that consists of a substance that has a high number of molecules that are very close to each other will be denser than a substance that contains fewer molecules that are farther apart in the same size container.
Based on this, we can say that to measure density, we must measure the mass per unit volume. However, the density of a substance is not always the same. It can be affected by factors such as temperature and pressure.
In most cases, an increase in temperature will increase the distance between the molecules of a substance, thus changing its density. This is why warm water will rise above cold water; warm water is less dense than its colder counterpart. This phenomenon, called thermal stratification, is evident in lakes during the summer months when the water surface is 25° Celsius / 77° Fahrenheit or more, while at depth the water temperature is 10° Celsius / 50° Fahrenheit.
The less dense surface layer is called the epilimnion. The deeper, denser layer is called the hypolimnion and the layer in between them, where there is an abrupt temperature change, is called the metalimnion, or more commonly, a thermocline. In clear water, the variation in the density between the warm and cold water can be seen.
Density variations in liquids and gases due to temperature and pressure changes are important for every diver to understand, especially when such changes affect breathing gases, such as Nitrox.