NIV works by providing continuous positive airway pressure (CPAP) or bilevel positive airway pressure (BiPAP) to keep the airways open and support breathing. CPAP delivers a constant pressure throughout the respiratory cycle, while BiPAP provides two levels of pressure: higher during inhalation and lower during exhalation. These modes help in reducing the work of breathing and improving gas exchange.