The airway mucin Muc5b (but not Muc5ac) is required for mucociliary clearance, defence against bacterial infection in the airways and middle ear, and maintenance of immune homeostasis in the lungs; Muc5b deficiency causes accumulation of apoptotic macrophages, impairment of phagocytosis and reduced production of interleukin-23, leading to infection and inflammation. The mucosal surfaces in the lungs are a first line of defence against airborne pathogens but overproduction of mucus can itself cause respiratory disease. This study identifies a specific glycoprotein component of airway mucus, called Muc5b, as essential for mucociliary clearance in mice. Surprisingly Muc5b also contributes to innate defence against bacterial infection through the regulation of macrophage function both in mice and in humans with allergic asthma. Absence of Muc5b causes materials to accumulate in the airways, culminating in chronic infection by multiple bacterial species. This work could have relevance for the treatment of airway diseases. Respiratory surfaces are exposed to billions of particulates and pathogens daily. A protective mucus barrier traps and eliminates them through mucociliary clearance (MCC)1,2. However, excessive mucus contributes to transient respiratory infections and to the pathogenesis of numerous respiratory diseases1. MUC5AC and MUC5B are evolutionarily conserved genes that encode structurally related mucin glycoproteins, the principal macromolecules in airway mucus1,3. Genetic variants are linked to diverse lung diseases4,5,6, but specific roles for MUC5AC and MUC5B in MCC, and the lasting effects of their inhibition, are unknown. Here we show that mouse Muc5b (but not Muc5ac) is required for MCC, for controlling infections in the airways and middle ear, and for maintaining immune homeostasis in mouse lungs, whereas Muc5ac is dispensable. Muc5b deficiency caused materials to accumulate in upper and lower airways. This defect led to chronic infection by multiple bacterial species, including Staphylococcus aureus, and to inflammation that failed to resolve normally7. Apoptotic macrophages accumulated, phagocytosis was impaired, and interleukin-23 (IL-23) production was reduced in Muc5b−/− mice. By contrast, in mice that transgenically overexpress Muc5b, macrophage functions improved. Existing dogma defines mucous phenotypes in asthma and chronic obstructive pulmonary disease (COPD) as driven by increased MUC5AC, with MUC5B levels either unaffected or increased in expectorated sputum1,8. However, in many patients, MUC5B production at airway surfaces decreases by as much as 90%9,10,11. By distinguishing a specific role for Muc5b in MCC, and by determining its impact on bacterial infections and inflammation in mice, our results provide a refined framework for designing targeted therapies to control mucin secretion and restore MCC.