What is a capacitor and how does a capacitor works?
A capacitor in its simplest form consists of two parallel conducting plates separated by a non-conducting material called a dielectric.

What is a Capacitor?
A capacitor is a device that stores electrical energy in the form of an electric field, formed when there is a built up of opposite charges on its plates.
In the following diagram, one plate has an excess electrons that causes creation of negative charges and the other plate has an excess of protons that causes creation of positive charges.

Charges are carried by electrons and protons. If an object contains an equal number of electrons and protons, their charges cancel each other and the net charge of the object will be zero.
A capacitor is also defined as a device designed to introduce a known value of capacitance into a circuit. In storing electrical energy, a capacitor offers opposition to the flow of current.
Capacitance of a Capacitor.
The capacitance of a capacitor is the ability of a capacitor to store electrical energy. Since a capacitor offers opposition to flow of current, capacitance is also defined as the ability of a capacitor to oppose the flow of current.
The capacitance of a capacitor is measured in farads. The larger the value of capacitance of a capacitor, the more energy that can be stored by a capacitor and also the greater the opposition that is given to the flow of current.
The total opposition given to flow of current by a capacitor is called capacitive reactance. Capacitive reactance is measured in ohms, just like resistance.
How does a capacitor works?
When an uncharged capacitor (a capacitor that contains an equal number of electrons and protons on each of its plates) is connected to a source of voltage like a battery.
The positive side of the battery attracts electrons from one plate of a capacitor, leaving the plate with more protons than electrons.
At the same time, the negative side of a battery repels electrons away from it, causing the other plate to have more electrons than protons.

Recall that when a plate contains an equal number of electrons and protons, the charges on protons and electrons cancel each other and the plate is regarded as neutral.
If a plate contains more electrons than protons, it is negatively charged. If a plate contains more protons than electrons, it is positively charged.
The creation of opposite charges on the two plates of a capacitor creates an electric field, which is a sign of energy stored by a capacitor. This energy is released by a capacitor whenever certain conditions are meet in a particular circuit.
Capacitor in DC circuits.
Direct Current electricity is a type of electricity in which current flows in only one direction. Direct current and voltage do not vary in magnitude.
When a capacitor is connected to a DC source, current only flows while the capacitor is charging and stops flowing when the capacitor is charged to the supply voltage.
Since current only flows while the capacitor is charging and stops when it is fully charged, in this way, a capacitor blocks DC current.
A capacitor has a dielectric material between its plates that prevents current to pass through. During charging and discharging, electrons are only occupy one plate and others leaving the other plate.
Capacitor in AC circuits.
Alternating Current electricity is a type of electricity in which current reverses the direction of flow. The current and voltage of AC electricity vary in magnitude regularly.
When a capacitor is connected to an AC voltage source, the capacitor charges and discharge while the AC current and voltage are changing direction and magnitude. Current always flow in an AC circuit; in this way, a capacitor allows AC current.
Factors affecting capacitance of a capacitor.
When designing a capacitor, there are factors that are taken into account so that a capacitor with a known value of capacitance is manufactured. We have explained these factors in detail in the article, Factors Affecting Capacitance, you can check it out.
These factors are the cross-sectional area of the plates, the distance between the plates and the type of dielectric material used.

1.Cross-sectional area of plates (A).
The capacitance of a capacitor varies directly with the cross-sectional area of plates. This means that larger plates provide a higher value of capacitance of a capacitor than a smaller cross-sectional area plates.
2.Distance between plates (d).
The capacitance of a capacitor varies inversely with the distance between plates. As the distance between plates is increased, the capacitance decreases
3.Type of dielectric material.
The capacitance of a capacitor depends on the dielectric material used. Dielectric material provides an easy establishment of an electric field and also prevents the movement of electrons directly to the other plate. When iron is used as a dielectric material it provides a higher capacitance than air.
Dielectric material is measured based on permittivity (Eo.Er), which is the ease with which an electric field can be established through a material. The larger the permittivity value, the larger also the capacitance is.
To calculate the value of capacitance of a capacitor, the three factors are combined in the formula:

After finding the value of capacitance of a capacitor, we can find the capacitive reactance (Xc) offered by the capacitor in a particular circuit using the formula.

Types of Capacitors.
Capacitors are grouped into fixed and variable capacitors. Fixed capacitors have a capacitance value that cannot be varied, while variable capacitors have a capacitance value that can be varied or tuned between zero and their maximum values.
In Capacitors, we have polarized and non polarized capacitors. Polarized capacitors are capacitors used in DC circuit only, they have definite poles that indicate the positive and negative points for connection to DC voltage sources.
Non-polarized capacitors are capacitors that are used both in DC and AC circuit, Non polarized capacitors have no definite poles, they can are connected to a circuit either way.
Based on the material used as dielectric, we have various capacitors such as air, mica, paper, ceramic, plastic, titanium and electrolytic capacitors.