Electrocardiogram (ECG) gives essential information about different cardiac conditions of the human heart. Its analysis has been the main objective among the research community to detect and prevent life threatening cardiac circumstances. Traditional signal processing methods, machine learning and its subbranches, such as deep learning, are popular techniques for analyzing and classifying the ECG signal and mainly to develop applications for early detection and treatment of cardiac conditions and arrhythmias. A detailed literature survey regarding ECG signal analysis is presented in this paper. We first introduce a stages-based model for ECG signal analysis where a survey of ECG analysis related work is then presented in the form of this stage-based process model. The model describes both traditional time/frequency-domain and advanced machine learning techniques reported in the published literature at every stage of analysis, starting from ECG data acquisition to its classification for both simulations and real-time monitoring systems. We present a comprehensive literature review of real-time ECG signal acquisition, prerecorded clinical ECG data, ECG signal processing and denoising, detection of ECG fiducial points based on feature engineering and ECG signal classification along with comparative discussions among the reviewed studies. This study also presents a detailed literature review of ECG signal analysis and feature engineering for ECG-based body sensor networks in portable and wearable ECG devices for real-time cardiac status monitoring. Additionally, challenges and limitations are discussed and tools for research in this field as well as suggestions for future work are outlined. INDEX TERMS ECG analysis, cardiac arrhythmias, QRS and ST detection, ECG classification, deep learning.