The alveoli are highly elastic structures in the parenchyma of the lungs that are the functional site of gas exchange. As the alveoli fill with air during inhalation they expand, and as air leaves the lung with exhalation, the alvoli return to their non-inflated size. The reason for the elasticity of the alveoli is a protein found in the extracellular matrix of the alveoli, called elastin, as well as the surface tension of water molecules on the alveoli themselves.
Surface Tension in the Lung
Surface tension is the force exerted by water molecules on the surface of the lung tissue as those water molecules pull together. Water (H2O) is a highly polar molecule, so it forms strong covalent bonds with other water molecules. The force of these covalent bonds effectively creates an inward force on surfaces, such as lung tissue, with the effect of lowering the surface area of that surface as the tissue is pulled together. As the air inside the lungs is moist, there is considerable surface tension within the tissue of the lungs. Because the alveoli of the lungs are highly elastic, they do not resist surface tension on their own, which allows the force of that surface tension to deflate the alveoli as air is forced out during exhalation by the contraction of the pleural cavity.
Pulmonary Surfactant
The force of surface tension in the lungs is so great that without something to reduce the surface tension, the airways would collapse after exhalation, making re-inflation during inhalation much more difficult and less effective. Collapse of the lungs is called alectasis. Fortunately, the type II epithelial cells of the alveoli continually secrete a molecule called surfactant that solves this problem.
Surfactant is a lipoprotein molecule that reduces the force of surface tension from water molecules on the lung tissue. The main reason that surfactant has this function is due to a lipid called dipalmitoylphosphatidylcholine (DPPC) which contains hydophilic and hydrophobic ends. The hydrophilic ends are water soluable and attach to the water molecules on the surface of the lungs. The hydrophilic ends are water insoluable and face towards the air and pull away from the water. The net result is that the surface tension of the lungs from water is reduced so that the lungs can still inflate and deflate properly without the possibility of collapse from surface tension alone.
As unborn humans grow and develop in the womb, they receive oxygen from the mother, so their lungs aren't fully functional right away. Of particular importance is the fact that they don't produce surfactant until 24 weeks of development and usually don't have enough built up to prevent lung collapse until 35 weeks of development. Therefore prematurely born infants are at a high risk of respiratory distress syndrome from airway collapse, which can cause death if untreated. It is treated through pulmonary surfactant replacement therapy and mechanical ventilator treatment until the infant's lungs are old enough to secrete enough surfactant to survive on their own. Other diseases may cause atelectasis, such as COPD, or any sort of lung trauma and inflammation that involves extensive damage to the pleural cavity or the lung parenchyma.
Diagram of an Alveoli
An alveoli with both cross-section and external views