Leaves contain chlorophyll and are the sites of photosynthesis in plants. Their broad, flattened surfaces gather energy from sunlight while apertures on the their undersides bring in carbon dioxide and release oxygen. The cells of a leaf are sandwiched in between two layers of epidermal cells, which provide the leaf with a waxy, nearly impermeable cuticle that protects against water loss. The only way for gases to diffuse in and out of the leaf is though small openings on the underside of the leaf, the stomata. These stomata can open and close according to the plant's needs. The tissues of the leaf in between the epidermal cells, into which gases diffuse from the stomata, are called mesophyll.
The mesophyll can be further broken down into two layers, the palisade layer and the spongy layer, both of which are packed with chloroplasts, the factories of photosynthesis. In the palisade layer, chloroplasts are lined in columns just below the epidermal cells, to facilitate the capture of light. The spongy layer is a tissue that also contains chloroplasts and other parenchyma cells, but the cells are less ordered and spread out, leaving large intracellular spaces. These intracellular spaces, along with the moist surface of mesophyll cells, facilitate the exchange of carbon dioxide and oxygen.
Overall, it is to the plant's advantage to maximize the gas exchange and sunlight trapping surface while keeping leaf thickness to a minimum so that gases can diffuse easily throughout the cells of the leaf (a process that occurs readily only when there are only a few layers of cells present).
Stomata, as mentioned above, are the structures through which gas exchange occurs in leaves. Each stoma is surrounded by two guard cells, which can open and close depending on environmental conditions. When moisture is plentiful, the guard cells swell with water, forcing the opening of the stoma open and allowing gas exchange to occur. When the plant loses too much water or water in the environment becomes less plentiful, the guard cells deflate, closing the stoma and preventing further water loss or gas exchange.
When the stomata are open, the plant can take in carbon dioxide from the air for photosynthesis and release oxygen (a byproduct of photosynthesis) back into the environment. While doing so, the plant also loses an enormous amount of water by evaporation. This process is called transpiration. To make up for this water loss, additional water is drawn in from the soil by the roots and passed upward through the plant by the xylem.