Derivation →
Let us consider a conductor of capacitor $C$ is given a charge $+q$ then the electric potential
$V=\frac{q}{C} \qquad(1)$
The work done in charging the conductor is stored as potential energy in the electric field in the vicinity of the conductor.
Let bring a small charge $dq$ from infinity to the surface of the conductor. Then the work done will be
$dW=V\:dq \qquad(2)$
From equation $(1)$ and equation $(2)$
$dW=\frac{q}{C} \:dq$
Therefore, the work done in increasing the charge on the conductor from $0$ to $q$ is
$W=\int dW$
$W=\frac{1}{C} \int_{0}^{q} q dq$
$W=\frac{1}{C} \left[ \frac{q^{2}}{2} \right]^{q}_{0}$
$W=\frac{1}{2} \frac{q^{2}}{C}$
This work is stored in the form of electric potential energy $U$. Then
$U=\frac{1}{2} \frac{q^{2}}{C}$
