Standard Stun Gun
Conventional stun guns have a fairly simple design. They are about the size of a flashlight, and they work on ordinary 9-volt batteries.
The batteries supply electricity to a circuit consisting of various electrical components. The circuitry includes multiple transformers, components that boost the voltage in the circuit, typically to between 20,000 and 150,000 volts, and reduce the amperage. It also includes a oscillator, a component that fluctuates current to produce a specific pulse pattern of electricity. This current charges a capacitor. The capacitor builds up a charge, and releases it to the electrodes, the "business end" of the circuit.
The electrodes are simply two plates of conducting metal positioned in the circuit with a gap between them. Since the electrodes are positioned along the circuit, they have a high voltage difference between them. If you fill this gap with a conductor (say, the attacker's body), the electrical pulses will try to move from one electrode the other, dumping electricity into the attacker's nervous system.
Cattle prods are similar to stun guns in design -- they apply an electrical current across two electrodes -- but they serve a completely different function. A stun gun uses an electrical charge to incapacitate someone, while a cattle prod applies a charge to get a person or animal moving. A cattle prod only causes pain, it does not significantly affect the muscles and nervous system of the body.
These two devices differ mainly in voltage. The voltage in a stun gun is high enough to dump electricity into the entire body. The lower voltage in a cattle prod only shocks someone at the point of contact.