Accurate breath detection is crucial in sleep and respiratory physiology research and in several clinical settings. However, this process is technically challenging due to measurement and physiological artifacts and other factors such as variable leaks in the breathing circuit. Recently developed techniques to quantify the multiple causes of obstructive sleep apnea, require intermittent changes in airway pressure applied to a breathing mask. This presents an additional unique challenge for breath detection. Traditional algorithms often require drift correction. However, this is an empirical operation potentially prone to human error. This paper presents a new algorithm for breath detection during variable mask pressures in awake and sleeping humans based on physiological landmarks detected in the airflow or epiglottic pressure signal (Pepi). The algorithms were validated using simulated data from a mathematical model and against the standard visual detection approach in 4 healthy individuals and 6 patients with sleep apnea during variable mask pressure conditions. Using the flow signal, the algorithm correctly identified 97.6% of breaths with a mean difference±SD in the onsets of respiratory phase compared to expert visual detection of 23±89ms for inspiration and 6±56ms for expiration during wakefulness and 10±74ms for inspiration and 3±28 ms for expiration with variable mask pressures during sleep. Using the Pepi signal, the algorithm correctly identified 89% of the breaths with accuracy of 31±156ms for inspiration and 9 ±147ms for expiration compared to expert visual detection during variable mask pressures asleep. The algorithm had excellent performance in response to baseline drifts and noise during variable mask pressure conditions. This new algorithm can be used for accurate breath detection including during variable mask pressure conditions which represents a major advance over existing time-consuming manual approaches. Introduction.