The heartbeat is regulated by the intrinsic factors and the extrinsic factors. The intrinsic factor is the sino-atrial node (SAN) located in the right atrium. It is called the pacemaker of the heart and is a bunch of cells responsible for generating impulse for the contraction of right atrial muscles. The impulse is then transmitted to the junction point of atrium and ventricle called the atrioventricular node (AVN) through which the impulse moves to both the ventricles via the Bundle of His to the Purkinje fibers located in the walls of the ventricles. These are responsible for the contraction of the ventricles. Thus, the contraction of atria and ventricles makes one heartbeat and is regulated by the sino-atrial node. That is why it is called the pacemaker of the heart.
The extrinsic factors are the Autonomic Nervous System (ANS) and the hormones. The parasympathetic nervous system of ANS induces slow heartbeat, called the bradycardia and the sympathetic nervous system of the ANS induces faster heartbeat called the tachycardia. Under non-stressful conditions, both of these system input equal effect and the heartbeat is normalized. Under the stressed condition, either of them will have an effect on the heartbeat. Neurohormones like acetylcholine decrease the heartbeat and epinephrine and norepinephrine increase the heartbeat.