Plants can obtain the CO2 necessary for photosynthesis via stomates. Stomates are openings which can be found on the upper or lower epidermis of a leaf, the size of which can be regulated by guard cells. During the daytime, the guard cells causing the stomata to open due to the presence of sunlight and humidity. Carbon dioxide can enter the leaf and diffuse to the palisade's and spongy cells where photosynthesis occurs in the chloroplast-rich cells located there. There are also air spaces within the leaf which allow the diffusion of carbon dioxide to the photosynthetic cells. Stomates can also be closed, especially during periods when water is scarce. This is a mechanism to enable a plant to survive these dry periods by preventing water loss.