Let $S(q)$ and $D(q)$ be supply and demand curves in terms of $q$, where $q$ is the quantity.

Then we calculate the producer and consumer surplus by using the following formulas:

$PS$ (producer surplus) = $\int_{0}^{\overline q} [\overline p - S(q)] dq$

$CS$ (consumer surplus) = $\int_{0}^{\overline q} [D(q) - \overline p] dq$

Where $\overline p$ and $\overline q$ are equilibrium prices and quantity.