We know that,
C=QV and hence
Q=CVHere, C is the capacitance of the capacitor, Q is the charge stored in it and V is the potential difference between the two plates of the capacitor.
Consider that the capacitor is getting charged slowly.
Let us consider an intermediate stage in which a charge of magnitude q is present on the capacitor and V be its potential difference.
Whenever some extra charge gets stored, the P.D. goes on increasing.
Hence, for the convenience of calculation, let us consider a very very small charge dq getting deposited.
Since it's very small, the change in P.D. can be ignored and can be considered as constant as V.
Work needs to be done in charging it. Let the small work done in depositing the charge dq be dW.
This work done gets stored in the form of potential energy P.E. in the capacitor.
Hence the small gain in P.E. is dW
We know that work done is w=qV
∴dW=Vdq.
substituting from the very 1st equation, we get,
dW=qC×dq
Hence the total work done in the complete charging is given by the intergral.
W=∫dW=∫qdqC
Since the min and max values of q are 0 and Q, we take them as limits.
∴W=∫Q0dW=∫Q0qdqC=Q22C=(CV)22C=12CV2