Stomata can be thought of as gates. This is why the size of the guard cells is so important. How the guard cells change in size is a simple matter of how much fluid they can hold - their turgor. Osmosis is the movement of water through a semi-permeable membrane (a membrane that allows small molecules like H2O through it, but not larger molecules) from higher to lower water potential. When guard cells have low water potential then water enters the cell and makes it a turgid cell. Due to their inner cell wall being thicker and more rigid, the guard cells bend away from each other when they fill with water and this opens a pore - the gates open.
So how does water potential change in guard cells? The guard cells use ATP driven proton (H+) pumps to efflux (eject) positively charged protons and hyperpolarise the plasma membrane. This activates inward potassium (K+) channels and so K+ ions enter the cell and decrease the water potential. Water moves by osmosis and causes the cell to expand.
To reverse this, anions such as chloride (Cl-) are released through channels in order to depolarise the plasma membrane. This deactivates the inward K+ channels and activates the outward channels so K+ ions are effluxed. The release of both anions and K+ increases water potential and leads to loss of turgor. The guard cells change from being turgid to being flaccid and stop bending away from each other - closing the gates.