Almost uniquely in the natural world, the coldest forms of water ice float on top of warmer forms of water, because ice is less dense than liquid water. Upon this simple natural law, all life on our planet depends.
The ratio of an object's mass to its volume is called its density. Denser objects sink relative to less dense objects, and vice versa. Helium balloons float in air, air balloons in water, solid ice floats above liquid water, but hot air balloons rise even in a standard atmosphere. Thus there are four major factors in considering a material's density: its atomic weight, the external pressure upon that object, its temperature, and its molecular structure.
1. Atomic weight
The first rule of density is that at a particular temperature and pressure, a given space will always be occupied by the same number of isolated atoms or molecules. In this case, the only difference in density will be due to difference of atomic or molecular weight.
Atomic number is the total number of protons in an atom of a given element. Atomic weight is the total number of both protons and neutrons in that atom. Different isotopes of the same element have the same atomic number, but different atomic weights. For example, the atomic number of uranium is 92. However, different isotopes of uranium have different atomic weights, with U-235 (92 protons, 143 neutrons) being particularly desirable for nuclear fission reactors, while U-238 (92 protons, 146 neutrons) is by far the more common isotope of uranium.
Molecular weight is the combined atomic weights of all atoms making up that molecule. For example, the molecular weight of water is that of two hydrogen atoms and one oxygen atom. So-called "heavy water" uses heavier isotopes of hydrogen which have a greater number of neutrons.
A marble made of uranium is far heavier than a marble made of gold, because the atomic weight of uranium is much greater than that of gold. In air, carbon dioxide sinks and helium rises, because the total atomic weight of carbon dioxide is greater than that of the nitrogen-oxygen mixture which makes up most air; while the atomic weight of helium is much less.
The second rule of density is that as external pressure increases, materials become denser. In fact, like temperature (below), pressure can cause materials to change state from gas to liquid, and even from liquid to solid. This can be approximately understood by visualising a material as a collection of molecules. The greater the pressure upon those molecules, the tighter together they are packed, and thus the greater their density.
We commonly make use of this tendency in industry. For example, hospitals and welders and balloon greeters alike make use of various components of air (helium, oxygen, nitrogen), which are commonly delivered in a liquid form very cold and under significant pressure to generally make it easier to transport. We open the valve, releasing the pressure: and at once the helium or oxygen or nitrogen becomes gaseous again.
Curiously, the greater the pressure upon water, the less likely it is to form ice or, another twist, the more likely that ice is to have liquid-like properties, as in glaciers. This is not an exception to the pressure rule, but a case where molecular structure supercedes both pressure and temperature.
The third rule of density is temperature. The general thermodynamic rule of density is that the colder it gets, the denser the material gets. In the ecosphere, the deeper the water, the greater the water pressure, the denser it will tend to be. Additionally, the deeper the water, the further away it gets from the sunlight which warms it, and so deep water also gets colder and colder, so long as it remains in its liquid form and above approximately 4 degrees Celsius (39 degrees Fahrenheit).
It takes an unusually high amount of heat energy for water to change temperature, a property known as heat capacity. In fact, among known chemical compounds, the specific heat capacity of water is surpassed only by that of ammonia. Because water can absorb so much heat energy before altering by so much as a degree in temperature, it acts as a strong climactic moderator, keeping the overall temperature of the earth from swinging too much.
4. Molecular structure
The final rule of density is molecular structure. In extreme cases, such as those found within a neutron star, this becomes subatomic structure, as gravitational forces overcome atomic forces. In terrestrial environments, however, molecular bonds between individual atoms play the most relevant roles in material structure. The nature of these bonds and how they interact with each other can sometimes result in what would seem to be paradoxical outcomes. In all nature, only three substances are known to become less dense in their solid state than in their liquid state: bismuth, gallium ... and water.
In water, two hydrogen atoms are joined to an oxygen atom with two covalent bonds, which means simply that electrons are shared in pairs between atoms to achieve greater stability. Usually covalent bonds exist between molecules of similar electronegativity, effectively balancing out the charge. However, the higher electronegativity of oxygen than hydrogen polarises the water molecule, which is what gives water its extremely high surface tension and also allows it to act as such an effective solvent.
As water gets golder, the proximity of water molecules becomes such that its polarity begins to interact primarily with itself, significantly decreasing its solvency for non-water molecules. (Thus the colder the water, the purer the water.) Once water reaches 3.98 degrees Celsius (39.16 degrees Fahrenheit), this strong polarity begins to create a crystal lattice which acts to keep molecules at a fixed distance from each other, making it approximately 9% less dense than liquid water. Once this crystal lattice structure has spread through the water, the result is ice. In the atmosphere, where the ice crystal has more room to expand, the result is often a snowflake.
In glaciers, the pressure upon this crystal lattice alters the bonds into a different type of ice crystal, one which has the ability to flow. This is one of many known crystal structures of water, but the only other one we can observe outside the laboratory.
Thus water does in fact tend to become denser, and thus to sink, right up until it hits 3.98 degrees Celsius: at which point inversion takes place, whereby the coldest water at the bottom becomes ice and floats to the surface, displacing warmer water which begins to sink in its turn. This process continually churns up nutrients from the bottoms of lakes and rivers and oceans, while at the same time usually preventing them from freezing completely solid.