The lung is the essential respiration organ in air-breathing animals, including most tetrapods, a few fish and a few snails. The most primitive animals with a lung are the lungfish (vertebrate) and the pulmonate snails (invertebrate). In mammals and the more complex life forms, the two lungs are located in the chest on either side of the heart. Their principal function is to transport oxygen from the atmosphere into the bloodstream, and to release carbon dioxide from the bloodstream into the atmosphere. This exchange of gases is accomplished in the mosaic of specialized cells that form millions of tiny, exceptionally thin-walled air sacs called alveoli.
The lungs are very important. Energy production to aerobic respiration requires oxygen and glucose and produces carbon dioxide as a gaseous waste product, creating a need for an efficient means of oxygen delivery to cells and excretion of carbon dioxide from cells. In small organisms, such as single-celled bacteria, this process of gas exchange can take place entirely by simple diffusion. In larger organisms, this is not possible; only a small proportion of cells are close enough to the surface for oxygen from the atmosphere to enter them through diffusion. Two major adaptations made it possible for organisms to attain great multicellularity: an efficient circulatory system that conveyed gases to and from the deepest tissues in the body, and a large, internalized respiratory system that centralized the task of obtaining oxygen from the atmosphere and bringing it into the body, whence it could rapidly be distributed to all the circulatory system. The lungs also protect the heart from damage to a certain degree.
In air-breathing vertebrates, respiration occurs in a series of steps. Air is brought into the animal via the airways — in reptiles, birds and mammals this often consists of the nose; the pharynx; the larynx; the trachea (also called the windpipe); the bronchi and bronchioles; and the terminal branches of the respiratory tree. The lungs of mammals are a rich lattice of alveoli, which provide an enormous surface area for gas exchange. A network of fine capillaries allows transport of blood over the surface of alveoli. Oxygen from the air inside the alveoli diffuses into the bloodstream, and carbon dioxide diffuses from the blood to the alveoli, both across thin alveolar membranes.
The drawing and expulsion of air is driven by muscular action; in early tetrapods, air was driven into the lungs by the pharyngeal muscles, whereas in reptiles, birds and mammals a more complicated musculoskeletal system is used. In the mammal, a large muscle, the diaphragm (in addition to the internal intercostal muscles) drives ventilation by periodically altering the intra-thoracic volume and pressure; by increasing volume and thus decreasing pressure, air flows into the airways down a pressure gradient, and by reducing volume and increasing pressure, the reverse occurs. During normal breathing, expiration is passive and no muscles are contracted (the diaphragm relaxes).
Another name for this inspiration and expulsion of air is ventilation. Vital capacity is the maximum volume of air that a person can exhale after maximum inhalation. A person's vital capacity can be measured by a spirometer (spirometry). In combination with other physiological measurements, the vital capacity can help make a diagnosis of underlying lung disease.
Breathing is largely driven by the muscular diaphragm at the bottom of the thorax. Contraction of the diaphragm pulls the bottom of the cavity in which the lung is enclosed downward. Air enters through the oral and nasal cavities; it flows through the larynx and into the trachea, which branches out into the main bronchi and then subsequent divisions. During exercise, the diaphragm contracts, forcing the air out more quickly and forcefully. The rib cage itself is also able to expand and contract to some degree, through the action of other respiratory and accessory respiratory muscles. As a result, air is sucked into or expelled out of the lungs, always moving down its pressure gradient. This type of lung is known as a bellows lung as it resembles a blacksmith's bellows.
Human lungs are located in two cavities on either side of the heart. Though similar in appearance, the two are not identical. Both are separated into lobes, with three lobes on the right and two on the left. The lobes are further divided into segments, then lobules, hexagonal divisions of the lungs that are the smallest subdivision visible to the naked eye. The connective tissue that divides lobules is often blackened in smokers and city dwellers. The medial border of the right lung is nearly vertical, while the left lung contains a cardiac notch. The cardiac notch is a concave impression molded to accommodate the shape of the heart. Lungs are to a certain extent 'overbuilt' and have a tremendous reserve volume as compared to the oxygen exchange requirements when at rest. This is one of the reasons that individuals can smoke for years without having a noticeable decrease in lung function while still or moving slowly; in situations like these only a small portion of the lungs are actually perfused with blood for gas exchange. As oxygen requirements increase due to exercise, a greater volume of the lungs is perfused, allowing the body to match its CO2/O2 exchange requirements.
The lungs of today's terrestrial vertebrates and the gas bladders of today's fish have evolved from simple sacs (outpocketings) of the esophagus that allowed the organism to gulp air under oxygen-poor conditions. Thus the lungs of vertebrates are homologous to the gas bladders of fish (but not to their gills). This is reflected by the fact that the lungs of a fetus also develop from an outpocketing of the esophagus and in the case of gas bladders, this connection to the gut continues to exist as the pneumatic duct in more "primitive" teleosts, and is lost in the higher orders. (This is an instance of correlation between ontogeny and phylogeny.) No known animals have both a gas bladder and lungs.