A capacitor is charged by connecting it to a battery or to a constant-voltage power supply to create a circuit. Charge flows to the capacitor from the battery or power supply until the potential difference across the capacitor is the same as the supplied voltage. If the capacitor is disconnected, it retains its charge and potential difference.
A real capacitor is subject to charge leaking away over time. However, for simplicity, while solving numerical problems sometimes it is assumed that an isolated capacitor retains its charge and potential difference indefinitely.
Figure 1 illustrates this charging process with a circuit diagram.
In this diagram, the lines represent conducting wires. The battery (power supply) is represented by its usual symbol, which is labeled with plus and minus signs indicating the potential assignments of the terminals and with the potential difference, V.
The capacitor is represented by the 2 parallel bars of equal size, which are labeled C.
This circuit also contains a switch. (see figure 1)
When the switch is between positions a and b, the battery is not connected and the circuit is open.
Charging: When the switch is at position a, the circuit is closed; the battery is connected across the capacitor and the capacitor charges.
Discharging: When the switch is at position b, the circuit is closed in a different manner. The battery is removed from the circuit, and the two plates of the capacitor are connected to each other, and charge can flow from one plate to the other through the wire, which now forms a physical connection between the plates. When the charge has dissipated on the two plates, the potential difference between the plates drops to zero, and the capacitor is said to be discharged.