An ECG, or electrocardiogram, is a test that records the electrical activity of the heart. It detects abnormalities in heart rhythm and can help diagnose conditions like heart attacks, damaged heart muscle, or an irregular heartbeat. The ECG is a painless and noninvasive test that provides important information about how well the heart is functioning.