Consider a capacitor of capacitance C, completely uncharged in the begning.

Charhing process of capacitor requires expanditure of energy because while charging a capacitor charge is transferred from plate at lower potential to plate at higher potential.

Now if we start charging capacitor by transporting a charge dQ from negative plate ti the positive plate then work is done against the potential difference across the plate.

If q is the amount of charge on the capacitor at any stage of charging process and φ is the potential difference across the plates of capacitor then magnitude of potential difference is φ=q/C.

Now work dW required to transfer dq is
dW=φdq=qdq/C

To charge the capacitor starting from the uncharged state to some final charge Q work required is
Integrating from 0 to Q
W=(1/C)∫qdq
=(Q^{2})/2C (14a)
=(CV^{2})/2
=QV/2

Which is the energy stored in the capacitor and can also be written as
U=(CV^{2})/2 ---(15)

From equation 14c,we see that the total work done is equal to the average potential V/2 during the charging process ,multiplied by the total charge transferred

If C is measured in Farads ,Q in coulumbs and V in volts the energy stored would in Joules

A parallel plate capacitor of area A and seperation d has capacitance

C=ε_{0}A/d

electric field in the space between the plates is
E=V/d or V=Ed

Putting above values of V and C in equation 14b we find
W=U=(1/2)(ε_{0}A/d)(Ed)^{2}
=(1/2)ε_{0}E^{2}(Ad)
=(1/2)ε_{0}E^{2}.V ---(16)

If u denotes the energy per unit volume or energy density then
u=(1/2)ε_{0}E^{2} x volume

The result for above equation is generally valid even for electrostatic field that is not constant in space.