The stoma (stomata – plural) is surrounded by a pair of guard cells. The structure of the guard cells is such that changes in turgor inside the cell cause changes in their shape. In general stomata open during daytime (in light) and close during the night (darkness).
Stomata open when osmotic pressure in guard cells becomes higher than that in surrounding cells due to increase in solute concentration inside guard cells.
Water is then drawn into guard cells by osmosis. Guard cells become turgid and extend. The thinner outer walls extend more than the thicker walls. This causes a bulge and stoma opens.
Stomata close when the solute concentration inside guard cells become lower than that of surrounding epidermal cells. The water moves out by osmosis, and the guard cells shrink i.e. lose their turgidity and stoma closes.