Assume you are hungry and you are willing to pay 5 dollars for one slice of pizza. However, you find that you can buy that slice for only 2 dollars. In that case, your total gain from buying that slice of pizza is 3 dollars because you were able to buy it for less than the value you put on it. This gain is called Consumer Surplus.
“Consumer Surplus is the difference between the maximum price consumers are willing to pay and the price they actually pay.”
-- Gwartney, et al., Microeconomics: Private and Public Choice, 14th Edition
Now consider the pizza market: individuals who are hungry and want to buy pizza, people who have different willingnesses to pay for one slice of pizza, some people who put more and some who put less value on that. Consequently, some have more and some have less gain (consumer surplus) by buying a slice of pizza. The summation of all these individual gains is called total consumer surplus in the entire market. In the following figure, the size of the triangular area shows the total consumer surplus gained by all the consumers in the market.
Assume P1 = $2 is the price of one slice of pizza. All the slices of pizza sold in the market (Q1) are purchased by the consumer who value the slice more than and equal to $2. Some consumers value it very highly ($8) and some value it less ($5). For each consumer, the gain is the difference between the value and the $2. Therefore, the area of the triangle between demand curve and price (P1) equals the summation of all gains. Clearly, if the value that a consumer puts on the slice pizza is $2 and he pays $2 for it, then the gain will be zero.
Note that we should distinguish between marginal value and total value of a good. At each point (at each quantity of good sold), the marginal value for the consumers is the height of the demand curve and the total value equals the summation of all those marginal values. Marginal gain equals the difference between marginal value and price. Therefore, total gain, which we call consumer surplus, equals the summation of all marginal gains.
In order to calculate the consumer surplus, we need to find the area between demand curve and market price, the area under the demand curve and above the price (horizontal line). As we can see in the graph, consumer surplus is affected by the price. The higher price makes the area smaller and causes lower consumer surplus. The lower price makes the area larger and causes higher consumer surplus.
So, in this example, consumer surplus can be calculated as: