A cavity in the lungs is an air-filled space within an area of lung
tissue that has undergone necrosis, typically surrounded by a
thickened wall. Cavities can result from infections (such as
tuberculosis, fungal infections, or bacterial abscesses),
malignancies, and certain autoimmune diseases like
granulomatosis with polyangiitis. The pathogenesis involves tissue
destruction, usually due to infection or inflammation, which leads
to localized death of lung tissue, creating an empty space. Cavities
can lead to symptoms such as chronic cough, fever, and, if
infected, production of purulent sputum or hemoptysis. Diagnosis is
primarily based on imaging, with chest X-rays or CT scans showing
an air-filled space with a thickened wall, and further confirmed
through microbiological cultures or biopsy if malignancy or specific
infections are suspected (Etesami)

Axial CT with Right Upper Lobe Aspergilloma
66- year-old malnourished, immunodeficient male presents with a chronic cough.
CT in the axial plane shows a 3.2cms right upper lobe mass with a rim of a crescentic accumulation of air in the dependant portionof the mass (magnified in the lower image) while the aspergilloma “sinks” to the most dependent portion of the cavity . This finding reflects an air -crescent sign and is consistent with a diagnosis of an aspergilloma
Ashley Davidoff TheCommonVein.net 293Lu 113528c
1 Month Later Decreased Consolidation and GGO Increased Cavity Size
CT in the axial plane, 1 month later shows shows decreased consolidation and cavity size has become more prominent.
Ashley Davidoff MD TheCommonVein.net 110Lu 136167
CT ? Right Lower Lobe Lung Abscess Hyperinflation of the Left Lower Lobe
Axial CT scan at the level of the lung bases in a 56-year-old male with an obstructing carcinoid tumor of the lingula shows a cavitating abscess cavity(d, blue arrowhead) with an air fluid level in the right lower lobe (b yellow arrowhead).
The left lower lobe is relatively lucent, reflecting compensatory hyperinflation secondary to the lingula atelectasis (c, black arrowhead)
Ashley Davidoff MD TheCommonVein.net 261Lu 118383cL
1Year Later Cavity with Aspergilloma in the Left Apex and Consolidation and Abscess in the Right Apex
CT of a 54 year old male shows a large left apical cavity with aspergilloma.  These findings are consistent with chronic pulmonary aspergillosis In the apex of the right lung, there is pneumonic consolidation and abscess formation .  Note the air fluid level in the right apex on axial soft tissue and lung windows. 
Ashley Davidoff TheCommonvein.net 225Lu 134202
Reactivation TB
CXR reveals a dense consolidation in the right upper lobe (red arrow) with questionable air-fluid level. No pneumothorax. No pleural effusions. Differential includes right upper lobe pneumonia or tuberculosis. CT is recommended for further evaluation if there is concern for a cavity.
Courtesy Joseph Cannella,
Dr. Christina LeBedis, MD, MS
TheCommonVein.net
Infection with M avium-intracellulare complex in a 44-year-old woman with malaise and a chronic cough. High-resolution CT scans of the right lung show multiple peripheral small nodules connected to branching linear opacities and a thick-walled cavity in the superior segment of the lower lobe. Note the thickening of the bronchial walls, bronchial dilatation, and mucus impaction. The diagnosis was confirmed with bronchoalveolar lavage.
Rossi, SE et al Tree-in-Bud Pattern at Thin-Section CT of the Lungs: Radiologic-Pathologic Overview RadioGraphicsVol. 25, No. 3 2005

132031.8.jpg

LUNG ABSCESS LIP HIV AIDS and LYMPHOMA
27 year old male with a history of perinatal HIV with intermittent highly active antiretroviral therapy (HAART) compliance with a CD4 count of < 50 with biopsy confirmed B cell lymphoma of the liver, s/p CHOP therapy , chronic esophageal strictures s/p dilatations, esophageal candidiasis, LIP, bronchiectasis pancreatitis, and portal vein and splenic vein thrombosis.
Initial Chest X-ray shows a diffuse reticular pattern with cystic changes dominant at the bases.
CT at that time confirmed the presence of diffuse cystic changes with the largest cysts at the lung bases. Ascites and splenomegaly are also present
He presented one month later with fever and neutropenia.
CT showed an abscess cavity in the right upper lobe in the right upper lobe, thickened distal esophagus with edematous wall, atrophic gastritis and ascites. Bronchovascular thickening along a bronchiectatic segment in the right upper lobe was present in the last CT
Ashley Davidoff MD TheCommonVein.net 017Lu 132031
70F-year old female presents 1 year after a severe episode with hemoptysis and bilateral lower lobe pulmonary infiltrates Current CT scan shows a large cavity in the left upper lobe and a shrunken left hemithorax
Ashley Davidoff MD TheCommonVein.net Wegeners-cavitation-018