Spirometry measures lung function by assessing the volume and speed of air inhaled and exhaled. It generates graphs of airflow and is used to diagnose respiratory conditions like asthma and detect obstructive and restrictive lung diseases. The test involves taking deep breaths into a mouthpiece and exhaling as forcefully as possible into the device multiple times. Results are analyzed to determine if values like forced vital capacity (FVC) and forced expiratory volume in one second (FEV1) are within normal ranges, with abnormally low values indicating lung dysfunction.