A solution to discriminate stance and swing in both healthy and abnormal gait using inertial sensors is proposed. The method is based on a two states hidden Markov model trained in a supervised way. The proposed method can generalize across different groups of subjects, without the need of parameters tuning. Leave-one-subject-out validation tests showed 20 ms and 16 ms errors on average in the determination of foot strike and toe off events across the three groups of subjects including 10 elderly, 10 hemiparetic patients and 10 Huntington's disease patients. The proposed methodology can be implemented online in portable devices to be used in clinical practice or in everyday personal health assessment.