Why does water expand when cooled while gases contract?
Usually, when things freeze - in other words turn from a liquid into a solid - they shrink or get smaller.
This is because, normally, if you make something hotter, it vibrates more. When it vibrates more, it tends to take up more space, so it tends to expand.
So, logically, if you cool something down, then the particles should move more slowly, collide and bounce off one another less hard and less frequently, and therefore, on average, spend more time closer together, making the material shrink.
Ice, on the other hand, is very unusual in that, as it gets colder, although the particles are certainly vibrating less for the reason explained above, it nonetheless expands or gets larger.
The reason for this is due to the strange shape of water molecules.
If you've ever seen a picture of a water molecule you'll know that it looks like a "Mickey Mouse" head, with an oxygen atom where Mickey Mouse's face is, and then two hydrogen atoms where his ears are.
The oxygen atom is slightly negative, and the hydrogens are slightly positively charged, so water molecules tend to stick together forming what are called hydrogen bonds.
Owing to the water molecule adopting that shape, the way water molecules tend to link together in the liquid state is to form a very open structure with big holes. That means, there's quite a lot of extra "empty" space.
When water freezes, the molecules get themselves into the most stable configurations or positions that have the minimum amount of energy in the resulting ice crystal.
It so happens that the arrangement of water molecules that best satisfies this requirement is one that takes up even more space. And so ice expands when it freezes.
In The case of gases,
Basic physics. When a gas (like you find in balloons) is cooled, the gas particles essentially slow down and push on each other less. This makes them be closer together. When all the air molecules get closer together, the volume of the balloon shrinks.