An apparatus and a method for the detection of inspiratory and expiratory half cycles in breathing are disclosed. The apparatus comprises an air source adapted to selectively provide pressurized breathable air to a patient a flow detecting device configured to sense the respiratory airflow from the patient and to generate an airflow signal indicative of airflow of a breathing cycle, and a microprocessor programmed to perform the following steps provisionally taking the start of inspiration as the time that inspiratory airflow exceeds a predetermined threshold, rejecting the start of inspiration if the flow then falls below zero again before the total volume reaches a predetermined value, provisionally taking the start of expiration as the time that expiratory airflow falls below zero, and rejecting the start of expiration if the airflow then goes above a predetermined value in the inspiratory direction before the total volume expired reaches a predetermined value.