In mainstream economics, economic surplus, also known as total welfare or total social welfare or Marshallian surplus (after Alfred Marshall), is either of two related quantities: 
 Consumer surplus, or consumers' surplus, is the monetary gain obtained by consumers because they are able to purchase a product for a price that is less than the highest price that they would be willing to pay.
 Producer surplus, or producers' surplus, is the amount that producers benefit by selling at a market price that is higher than the least that they would be willing to sell for; this is roughly equal to profit (since producers are not normally willing to sell at a loss and are normally indifferent to selling at a break-even price).
The sum of consumer and producer surplus is sometimes known as social surplus or total surplus; a decrease in that total from inefficiencies is called deadweight loss.

Overview 
In the mid-19th century, engineer Jules Dupuit first propounded the concept of economic surplus, but it was the economist Alfred Marshall who gave the concept its fame in the field of economics.

On a standard supply and demand diagram, consumer surplus is the area (triangular if the supply and demand curves are linear) above the equilibrium price of the good and below the demand curve. This reflects the fact that consumers would have been willing to buy a single unit of the good at a price higher than the equilibrium price, a second unit at a price below that but still above the equilibrium price, etc., yet they in fact pay just the equilibrium price for each unit they buy.

Likewise, in the supply-demand diagram, producer surplus is the area below the equilibrium price but above the supply curve. This reflects the fact that producers would have been willing to supply the first unit at a price lower than the equilibrium price, the second unit at a price above that but still below the equilibrium price, etc., yet they in fact receive the equilibrium price for all the units they sell.

History
Early writers of economic issues used surplus as a means to draw conclusions about the relationship between production and necessities. In the agricultural sector surplus was an important concept because this sector has the responsibility to feed everyone plus itself. Food is notable because people only need a specific amount of food and can only consume a limited amount. This means that excess food production must overflow to other people, and will not be rationally hoarded. The non-agricultural sector is therefore limited by the agricultural sector equaling the output of food subtracting the amount consumed by the agricultural sector. 

William Petty used a broad definition of necessities, leading him to focus on employment issues surrounding surplus. Petty explains a hypothetical example in which there is a territory of 1000 men and 100 of those men are capable of producing enough food for all 1000 men. The question becomes, what will the rest of the men do if only 100 are needed to provide necessities? He thereby suggests a variety of employments with some remaining unemployed. 

David Hume approached the agricultural surplus concept from another direction. Hume recognized that agriculture may feed more than those who cultivate it, but questioned why farmers would work to produce more than they need. Forceful production, which may occur under a feudal system, would be unlikely to generate a notable surplus in his opinion. Yet, if they could purchase luxuries and other goods beyond their necessities, they would become incentivized to produce and sell a surplus. Hume did not see this concept as abstract theory, he stated it as a fact when discussing how England developed after the introduction of foreign luxuries in his History of England.

Adam Smith's thoughts on surplus drew on Hume. Smith noted that the desire for luxuries is infinite compared to the finite capacity of hunger. Smith saw the development in Europe as originating from landlords placing more importance on luxury spending rather than political power.

Consumer surplus

Consumer surplus is the difference between the maximum price a consumer is willing to pay and the actual price they do pay. If a consumer is willing to pay more for a unit of a good than the current asking price, they are getting more benefit from the purchased product than they would if the price was their maximum willingness to pay. They are receiving the same benefit, the obtainment of the good, at a lesser cost. An example of a good with generally high consumer surplus is drinking water. People would pay very high prices for drinking water, as they need it to survive. The difference in the price that they would pay, if they had to, and the amount that they pay now is their consumer surplus. The utility of the first few liters of drinking water is very high (as it prevents death), so the first few liters would likely have more consumer surplus than subsequent quantities.

The maximum amount a consumer would be willing to pay for a given quantity of a good is the sum of the maximum price they would pay for the first unit, the (lower) maximum price they would be willing to pay for the second unit, etc. Typically these prices are decreasing; they are given by the individual demand curve, which must be generated by a rational consumer who maximizes utility subject to a budget constraint. Because the demand curve is downward sloping, there is diminishing marginal utility. Diminishing marginal utility means a person receives less additional utility from an additional unit. However, the price of a product is constant for every unit at the equilibrium price. The extra money someone would be willing to pay for the number units of a product less than the equilibrium quantity and at a higher price than the equilibrium price for each of these quantities is the benefit they receive from purchasing these quantities. For a given price the consumer buys the amount for which the consumer surplus is highest. The consumer's surplus is highest at the largest number of units for which, even for the last unit, the maximum willingness to pay is not below the market price.

Consumer surplus can be used as a measurement of social welfare, shown by Robert Willig. For a single price change, consumer surplus can provide an approximation of changes in welfare. With multiple price and/or income changes, however, consumer surplus cannot be used to approximate economic welfare because it is not single-valued anymore. More modern methods are developed later to estimate the welfare effect of price changes using consumer surplus.

The aggregate consumers' surplus is the sum of the consumer's surplus for all individual consumers. This aggregation can be represented graphically, as shown in the above graph of the market demand and supply curves. The aggregate consumers' surplus can also be said to be the maxim of satisfaction a consumer derives from particular goods and services.

Calculation from supply and demand
The consumer surplus (individual or aggregated) is the area under the (individual or aggregated) demand curve  and above a horizontal line at the actual price (in the aggregated case, the equilibrium price).  If the demand curve is a straight line, the consumer surplus is the area of a triangle:

where Pmkt is the equilibrium price (where supply equals demand), Qmkt is the total quantity purchased at the equilibrium price, and Pmax is the price at which the quantity purchased would fall to 0 (that is, where the demand curve intercepts the price axis).   For more general demand and supply functions, these areas are not triangles but can still be found using integral calculus. Consumer surplus is thus the definite integral of the demand function with respect to price, from the market price to the maximum reservation price (i.e., the price-intercept of the demand function):

where  This shows that if we see a rise in the equilibrium price and a fall in the equilibrium quantity, then consumer surplus falls.

Calculation of a change in consumer surplus

The change in consumer surplus is used to measure the changes in prices and income. The demand function used to represent an individual's demand for a certain product is essential in determining the effects of a price change. An individual's demand function is a function of the individual's income, the demographic characteristics of the individual, and the vector of commodity prices. When the price of a product changes, the change in consumer surplus is measured as the negative value of the integral from the original actual price (P0) and the new actual price (P1) of the demand for product by the individual. If the change in consumer surplus is positive, the price change is said to have increased the individuals welfare. If the price change in consumer surplus is negative, the price change is said to have decreased the individual's welfare.

Distribution of benefits when price falls 

When supply of a good expands, the price falls (assuming the demand curve is downward sloping) and consumer surplus increases.  This benefits two groups of people: consumers who were already willing to buy at the initial price benefit from a price reduction, and they may buy more and receive even more consumer surplus; and additional consumers who were unwilling to buy at the initial price will buy at the new price and also receive some consumer surplus.

Consider an example of linear supply and demand curves.  For an initial supply curve S0, consumer surplus is the triangle above the line formed by price P0 to the demand line (bounded on the left by the price axis and on the top by the demand line).  If supply expands from S0 to S1, the consumers' surplus expands to the triangle above P1 and below the demand line (still bounded by the price axis).  The change in consumer's surplus is difference in area between the two triangles, and that is the consumer welfare associated with expansion of supply.

Some people were willing to pay the higher price P0.  When the price is reduced, their benefit is the area in the rectangle formed on the top by P0, on the bottom by P1, on the left by the price axis and on the right by line extending vertically upwards from Q0.

The second set of beneficiaries are consumers who buy more, and new consumers, those who will pay the new lower price (P1) but not the higher price (P0).  Their additional consumption makes up the difference between Q1 and Q0.  Their consumer surplus is the triangle bounded on the left by the line extending vertically upwards from Q0, on the right and top by the demand line, and on the bottom by the line extending horizontally to the right from P1.

Rule of one-half 
The rule of one-half estimates the change in consumer surplus for small changes in supply with a constant demand curve.  Note that in the special case where the consumer demand curve is linear, consumer surplus is the area of the triangle bounded by the vertical line Q = 0, the horizontal line  and the linear demand curve.  Hence, the change in consumer surplus is the area of the trapezoid with i) height equal to the change in price and ii) mid-segment length equal to the average of the ex-post and ex-ante equilibrium quantities.  Following the figure above,

where:
 CS = consumers' surplus;
 Q0 and Q1 are, respectively, the quantity demanded before and after a change in supply;
 P0 and P1 are, respectively, the prices before and after a change in supply.

Producer surplus 
Producer surplus is the additional benefit that the owners of production factors and product providers bring to producers due to the differences between production, the supply price of the product, and the current market price. The difference between the amount actually obtained in a market transaction and the minimum amount it is willing to accept with the production factors or the products provided.

Calculation of producer surplus 
Producer surplus is usually expressed by the area below the market price line and above the supply curve. In Figure 1, the shaded areas below the price line and above the supply curve between production zero and maximum output Q1 indicate producer surplus. Among them, OP1EQ1 below the price line. This indicates that the total revenue is the minimum total payment actually accepted by the manufacturer. The area OPMEQ1 below the S curve is the minimum total revenue that the manufacturer is willing to accept. In Figure 1, the area enclosed by the market price line, the manufacturer's supply line, and the coordinate axis is the producer surplus. Because the rectangle OP1EQ1 is the total revenue actually obtained by the manufacturer, that is, A + B, and the trapezoid OPMEQ. The minimum total profit that the manufacturer is willing to accept, that is, B, so A is the producer surplus.

Obviously, the manufacturer produces and sells a certain quantity of Q1 goods at the market price P1. The manufacturer has reduced the quantity of goods for Q1, which means that the manufacturer has increased the production factors or production costs equivalent to the amount of AVC·Q1. However, at the same time, the manufacturer actually obtains a total income equivalent to the total market price P1·Q1. Since AVC is always smaller than P1, from the production and sales of goods in Q1, manufacturers not only get sales revenue equivalent to variable costs, but also get additional revenue. This part of the excess income reflects the increase in the benefits obtained by the manufacturers through market exchange. Therefore, in economics, producer surplus is usually used to measure producer welfare and is an important part of social welfare.

Producer surplus is usually used to measure the economic welfare obtained by the manufacturer in the market supply. When the supply price is constant, the producer welfare depends on the market price. If the manufacturer can sell the product at the highest price, the welfare is the greatest. As part of social welfare, the size of the producer surplus depends on many factors. Generally speaking, when other factors remain constant, an increase in market price will increase producer surplus, and a decrease in supply price or marginal cost will also increase producer surplus. If there is a surplus of goods, that is, people can only sell part of the goods at market prices, and producer surplus will decrease.

Obviously, the sum of the producer surplus of all manufacturers in the market constitutes the producer surplus of the entire market. Graphically, it should be expressed as the area enclosed by the market supply curve, the market price line and the coordinate axis.

See also 

 Deadweight loss
 Gross operating surplus
 Induced demand
 Price discrimination
 Price support
 Shortage
 Surplus product
 Surplus value
 Utility
 Value added
 Welfare economics
 Economic rent
 Surplus sharing

References
 Bade, R., & Parkin, M. (2017). Essential Foundations of Economics (8th ed.). Pearson.

 Corporate Finance Institute. (2021, March 26). Consumer Surplus and Producer Surplus.

Further reading
 Henry George, Progress and Poverty
 Modern Microeconomics, A.Koutsyiannis
 Microeconomic Theory, A Mathematical Approach, James M. Henderson and Richard E. Quandt

Microeconomics
Welfare economics
Corporate finance