Each stoma is surrounded by guard cells. When the guard cells are filled with water they swell. This makes the stomata open, and allows gas exchange to happen. When there is a shortage of water, the guard cells shrink. This closes the stomata, so less water vapour is lost through the pores.