A system for automatically recognizing three classes of different cardiac arrhythmias based on electrocardiogram (ECG) was proposed in this paper. The Hidden Markov model (HMM) was applied to the recognition of heartbeats from electrocardiogram (ECG). Some ECG features developed in existing papers are adopted here. The four heartbeat cases including the normal (NORM), bundle branch block (BBB) which includes left bundle branch block (LBBB) and the right bundle branch block (RBBB), the ventricular premature contractions (VPC), and the atrial premature contractions (APC) are recognized. In the experiment in this paper, the ECG data in the MIT - BIH Arrhythmia Database is applied by the proposed method. The experimental results showed that the proposed method performed well and had very excellent recognition rate for the concerning heartbeat cases.