This paper presents a new method for automatic identification of the inspiratory and expiratory breathing phases in lung sound recordings. Adventitious lung sounds (wheezes and crackles), superimposed on the breath sounds, are generally an early indication of the disease, and their timing in the breathing cycle (early/mid/late inspiratory or expiratory) has clinical significance for monitoring or diagnosing disease. Therefore, the identification of the phases of the breathing cycle is an essential step for clinical interpretation of pulmonary auscultation. The proposed algorithm is designed to be robust in the presence of adventitious lung sounds or where the breath sounds may be noisy compared to healthy lung sounds. The algorithm uses the Savitzky & Golay (SG) filter to estimate the second derivative of the lung sound signal then calculates its normalized absolute value. A threshold value is used to clip any large amplitude peaks and, following low-pas filtering, the breathing phases are visible in the plotted signal. A rule-based approach to locating peaks and troughs is then used to identify inspirations and expirations. The performance of the method is evaluated using four different datasets: (a) a longitudinal dataset recorded from 19 subjects with a diagnosis of idiopathic pulmonary fibrosis (IPF), (b) a cross-sectional dataset recorded from 55 subjects who were referred for high-resolution computed tomography (HRCT) scan of the chest for various clinical indications, (c) a longitudinal dataset recorded from 10 healthy subjects, and (d) an open access lung sounds dataset containing recordings from 41 subjects with wheeze (9 with chronic obstructive pulmonary fibrosis and 32 with asthma). On average for inspiratory phase identification the algorithm had a sensitivity of (mean (standard deviation)) 92.84 (12.88)%, positive predictive value of 90.64(15.96)%, and F1-score of 90.67 (12.53)%. For identification of the expiratory phase, the algorithm had an average sensitivity of 92.19 (13.44)%, an average positive predictive value of 91.55 (15.23)%, and an average F1-score of 90.89 (12.45)%. The method shows good potential for automatic identification of breathing phases in recorded lung sounds.