With inverse demand $P(q)$, price $p$ and quantity bought $Q$ (where $P(Q) = p$): $$CS = \int_0^Q \big(P(q) - p\big)\,dq = \int_p^{P_{\max}} Q(P)\,dP.$$ When the price falls from $p_0$ to $p_1$, consumer surplus rises by $\Delta CS = \int_{p_1}^{p_0} Q(P)\,dP$.
💡 Why it works
The height of the demand curve at quantity $q$ is the most someone would pay for the $q$-th unit. Buying it at price $p$ leaves a gain of $P(q) - p$. A thin slice of units of width $dq$ gives a gain of $(P(q) - p)\,dq$, and adding all the slices from the first unit to the last unit bought is the integral. The second formula adds the same area in horizontal slices: at each price level $P$ above $p$, the strip has length $Q(P)$.
$P(q) - p$ for demand $P = 20 - 2q$ and price \$8. The area from 0 to $Q = 6$ is consumer surplus, \$36. Past $q = 6$ the integrand is negative: units buyers value at less than the price, which they don't buy.
Check: a trapezoid between quantities 16 and 24, height 4: $\tfrac{1}{2}(16 + 24)(4) = 80$.
Answer: \$80.
Market consumer surplus is the same integral under the market demand curve, which adds up every buyer's gain. That makes it the standard way to put a dollar value on what buyers gain or lose from a price change, a tax or a new product. It is exact when income effects are small; Compensating and Equivalent Variation shows what changes when they are not.
⚠️ Common mistake
Integrating the demand curve from 0 to $Q$ without subtracting the price. That gives total willingness to pay: \$84 for the first example, not \$36. Buyers keep only the part above the price; the rectangle $p \times Q = 8 \times 6 = 48$ is what they pay. Check: consumer surplus must be smaller than total willingness to pay by exactly the amount spent.
Practice
Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.