The temperature of a substance is a measure of the average kinetic energy (energy of movement) of the molecules within it. When molecules have less kinetic energy, they are moving slower on average and thus the effect of collisions between molecules is decreased. This allows them to stay closer to each other. Therefore, in most cases - as with metal - a decrease in temperature causes objects to shrink, or contract. However, when water freezes it undergoes a state change; that is, it turns into a solid: ice. This solid is less dense (the molecules have lots of space between each other) than the liquid form of water because the molecules form a crystalline structure when they freeze, similar to what you'd see in a snowflake. A lower density means that the molecules take up more space and therefore, water expands when it turns into ice.