The action potential is generated in voltage-gated ion channels that are present in the plasma membrane of a cell. These ion channels are activated by changes in the electrical potential of the membrane near the channel.
When an external event causes the membrane electrical potential to increase and depolarize, the voltage-gated ion channels open and cause an influx of sodium ions into the axon. This eventually causes depolarization of the membrane and a reversal of the membrane's electrical polarity. Thereafter, the sodium channels close and the potassium channels open, resulting in an exodus of potassium ions out of the axon, and depolarization of the axon. This entire process of potential increase and decrease is called the action potential.