GASES
Gases don't have a fixed shape or fixed volume in the way that liquids and solids do. They will spread out and their volume increases until they disperse.
What's happening?
Everything around us is made of molecules. In a solid the molecules are packed tightly together, in a liquid the molecules move around more energetically and in a gas there is a lot of space between molecules and they flow around freely.
When a substance is heated the molecules start to move around more, they take up more space and the substance expands. It is not the molecules themselves that get bigger, but the room they need to move around. The heat that is applied provides the molecules with the energy they need to increase their movement.
In the same way, if things are cooled energy is extracted as heat, and eventually, the substance will change from gas to liquid to solid.
A good example of this occurring naturally is steam condensing as water on a cold surface in a bathroom. The warm steam meets the cold mirror surface, which conducts the heat of the steam away and water droplets are formed.
A good example of this happening mechanically (by artificial means) is a vapour compression refrigeration system - your fridge at home.