At rest, your cells have more potassium ions inside than sodium ions, and there are more sodium ions outside the cell.
Potassium ions are negative, so the inside of a cell has a slightly negative charge. Sodium ions are positive, so the area immediately outside the cell membrane is positive. There isn't a strong enough charge difference to generate electricity, though, in this resting state.
When the body needs to send a message from one point to another, it opens the gate. When the membrane gate opens, sodium and potassium ions move freely into and out of the cell.
Negatively charged potassium ions leave the cell, attracted to the positivity outside the membrane, and positively charged sodium ions enter it, moving toward the negative charge. The result is a switch in the concentrations of the two types of ions -- and rapid switch in charge. It's kind of like switching between a 1 and 0 -- this flip between positive and negative generates an electrical impulse. This impulse triggers the gate on the next cell to open, creating another charge, and so on. In this way, an electrical impulse moves from a
nerve in your stubbed toe to the part of your brain that senses
pain.