Electrical impulses are generated through the movement of ions, such as sodium (Na+) and potassium (K+), across the cell membrane. This process is regulated by ion channels and the sodium-potassium pump. When a neuron or muscle cell is stimulated, ion channels open, allowing Na+ to rush into the cell, causing depolarization. This depolarization propagates along the cell membrane as an action potential.