Nerve impulses are generated when a neuron is stimulated by a chemical, mechanical, or electrical signal. This stimulation causes a change in the neuron's resting membrane potential. When the membrane potential reaches a certain threshold, voltage-gated ion channels open, allowing sodium ions to rush into the cell. This rapid influx of sodium ions depolarizes the membrane, creating the action potential.