A Riemann sum approximates the area under a curve by adding up the areas of thin rectangles. As the rectangles get thinner, the sum approaches the exact definite integral.
$$\int_a^b f(x)\,dx \approx \sum_{i=1}^{n}f(x_i^*)\,\Delta x, \qquad \Delta x = \frac{b - a}{n}$$
The only question is where in each subinterval you measure the height \( f(x_i^*) \).
In this guide you will compute every common version on one running example, see why the errors behave the way they do, take the limit of a Riemann sum to get an exact integral, and practice the table-data questions that show up on exams.
The setup in symbols
Split \( [a, b] \) into \( n \) equal subintervals of width \( \Delta x = \frac{b - a}{n} \). The grid points are
$$x_i = a + i\,\Delta x, \qquad i = 0, 1, \dots, n$$
so \( x_0 = a \) and \( x_n = b \). The \( i \)-th subinterval is \( [x_{i-1}, x_i] \). A left sum uses \( x_{i-1} \), a right sum uses \( x_i \), and a midpoint sum uses \( \frac{x_{i-1} + x_i}{2} \). There are always \( n \) rectangles but \( n + 1 \) grid points, which is a common source of off-by-one errors.
Why it works
Each rectangle has the right width but a slightly wrong height, because the curve changes across the subinterval while the rectangle stays flat. The error in one rectangle is roughly (change in \( f \) across the strip) times (width), and both of those factors shrink as \( n \) grows. Adding \( n \) such errors still leaves a total that goes to zero, so every reasonable choice of sample point gives the same limit. That common limit is the definite integral.
The running example
\( f(x) = x^2 \) on \( [0, 2] \) with \( n = 4 \). Then \( \Delta x = 0.5 \) and the grid points are \( 0, 0.5, 1, 1.5, 2 \). The exact answer is \( \int_0^2x^2\,dx = \frac83 \approx 2.6667 \).
Left Riemann sum
Heights at left endpoints \( 0, 0.5, 1, 1.5 \):
$$L_4 = 0.5\left(0 + 0.25 + 1 + 2.25\right) = 1.75$$
Right Riemann sum
Heights at right endpoints \( 0.5, 1, 1.5, 2 \):
$$R_4 = 0.5\left(0.25 + 1 + 2.25 + 4\right) = 3.75$$
For an increasing function, left sums underestimate and right sums overestimate.
For a decreasing function it flips. Take \( f(x) = \frac1x \) on \( [1, 3] \) with \( n = 4 \), so \( \Delta x = 0.5 \). The left sum uses heights at \( 1, 1.5, 2, 2.5 \):
$$L_4 = 0.5\left(1 + \tfrac{1}{1.5} + \tfrac12 + \tfrac{1}{2.5}\right) = \frac{77}{60} \approx 1.2833$$
That is above the exact value \( \ln 3 \approx 1.0986 \), because each left endpoint is the highest point of its strip. (The exact value comes from the integral of 1/x.)
Midpoint rule
Heights at \( 0.25, 0.75, 1.25, 1.75 \):
$$M_4 = 0.5\left(0.0625 + 0.5625 + 1.5625 + 3.0625\right) = 2.625$$
Much closer, because the over- and under-shoots within each rectangle partly cancel.
Trapezoidal rule
Use trapezoids instead of rectangles. It equals the average of the left and right sums:
$$T_n = \frac{\Delta x}{2}\Big[f(x_0) + 2f(x_1) + \dots + 2f(x_{n-1}) + f(x_n)\Big]$$
$$T_4 = \frac{1.75 + 3.75}{2} = 2.75$$
Concavity decides the direction. Since \( x^2 \) is concave up, each trapezoid’s top edge lies above the curve, so the trapezoid rule overestimates. The midpoint rectangle can be tilted into a tangent-line trapezoid of equal area, which lies below the curve, so the midpoint rule underestimates. That is why \( M_4 = 2.625 < \frac83 < T_4 = 2.75 \). For a concave-down function, both inequalities reverse.
Simpson’s rule
Fit parabolas through groups of three points (\( n \) must be even). Weights follow the pattern \( 1, 4, 2, 4, \dots, 4, 1 \):
$$S_n = \frac{\Delta x}{3}\Big[f(x_0) + 4f(x_1) + 2f(x_2) + \dots + 4f(x_{n-1}) + f(x_n)\Big]$$
$$S_4 = \frac{0.5}{3}\left(0 + 4(0.25) + 2(1) + 4(2.25) + 4\right) = \frac83$$
Exact! Simpson’s rule is exact for polynomials up to degree 3.
A useful identity connects the methods: \( S_{2n} = \frac{2M_n + T_n}{3} \). Simpson’s rule is a weighted average of the midpoint and trapezoid rules, chosen so that their opposite errors cancel.
Comparison
| Method | \( n = 4 \) estimate | Error | Error shrinks like |
|---|---|---|---|
| Left | 1.75 | 0.917 | \( 1/n \) |
| Right | 3.75 | 1.083 | \( 1/n \) |
| Midpoint | 2.625 | 0.042 | \( 1/n^2 \) |
| Trapezoid | 2.75 | 0.083 | \( 1/n^2 \) |
| Simpson | 2.6667 | 0 | \( 1/n^4 \) |
Doubling \( n \) cuts the left/right error in half, the midpoint/trapezoid error by 4, and Simpson’s error by 16.
Error bounds
If \( |f''(x)| \le K \) on \( [a, b] \), then
$$|E_M| \le \frac{K(b - a)^3}{24n^2}, \qquad |E_T| \le \frac{K(b - a)^3}{12n^2}$$
and if \( |f^{(4)}(x)| \le K_4 \), Simpson’s error satisfies \( |E_S| \le \frac{K_4(b - a)^5}{180n^4} \). For the running example, \( f'' = 2 \), so the midpoint bound is \( \frac{2\cdot 8}{24\cdot 16} = \frac{1}{24} \approx 0.042 \) and the trapezoid bound is \( \frac{1}{12} \approx 0.083 \). Both match the actual errors exactly, which happens because \( f'' \) is constant. And since \( f^{(4)} = 0 \), Simpson’s error must be 0.
From sums to integrals
The definite integral is defined as the limit of Riemann sums:
$$\int_a^b f(x)\,dx = \lim_{n\to\infty}\sum_{i=1}^n f(x_i^*)\,\Delta x$$
In practice we evaluate it with the Fundamental Theorem of Calculus, but Riemann sums are how computers integrate functions that have no antiderivative, like \( e^{-x^2} \) (see the integral of e^(−x²)).
Example: computing the limit exactly
Here is the right sum for \( x^2 \) on \( [0, 2] \) with any \( n \). Now \( \Delta x = \frac2n \) and \( x_i = \frac{2i}{n} \), so each height is \( \frac{4i^2}{n^2} \):
$$\begin{aligned} R_n &= \sum_{i=1}^n \frac{4i^2}{n^2}\cdot\frac2n = \frac{8}{n^3}\sum_{i=1}^n i^2 \\ &= \frac{8}{n^3}\cdot\frac{n(n + 1)(2n + 1)}{6} \\ &= \frac{4(n + 1)(2n + 1)}{3n^2} \end{aligned}$$
The middle step uses the sum-of-squares formula. As a check, \( n = 4 \) gives \( \frac{4\cdot5\cdot9}{48} = 3.75 \), the same \( R_4 \) as before. As \( n \to \infty \), the fraction behaves like \( \frac{8n^2}{3n^2} \), so
$$\lim_{n\to\infty}R_n = \frac83$$
which is the exact integral. This is how integrals were computed before the Fundamental Theorem, and it is a favorite exam question.
Riemann sums from a table
Exam problems often give data instead of a formula. A car’s velocity in m/s is recorded every 2 seconds:
| \( t \) (s) | 0 | 2 | 4 | 6 |
|---|---|---|---|---|
| \( v(t) \) (m/s) | 0 | 10 | 16 | 20 |
The distance traveled is \( \int_0^6 v(t)\,dt \). With three subintervals of width 2:
- Left sum: \( 2(0 + 10 + 16) = 52 \) meters.
- Right sum: \( 2(10 + 16 + 20) = 92 \) meters.
- Trapezoid: the average, \( 72 \) meters.
Since the velocity increases throughout, the true distance lies between 52 and 92 meters. The units come from multiplying the height (m/s) by the width (s). If the table spacing is uneven, compute each rectangle separately with its own width instead of factoring out one \( \Delta x \).
Common mistakes
- Wrong \( \Delta x \). It is \( \frac{b - a}{n} \), the width of one strip, not the number of grid points.
- Using the wrong endpoints. A left sum never uses \( f(b) \), and a right sum never uses \( f(a) \). Write out the sample points before evaluating.
- Confusing midpoint with trapezoid. The trapezoid rule is the average of the left and right sums. The midpoint rule evaluates \( f \) at the centers of the strips, which is a different number.
- Odd n in Simpson’s rule, or wrong weights. Simpson needs an even \( n \), weights \( 1, 4, 2, \dots, 4, 1 \), and a factor of \( \frac{\Delta x}{3} \), not \( \frac{\Delta x}{2} \).
- Forgetting that area can be negative. Where \( f < 0 \), a rectangle contributes a negative amount. A Riemann sum estimates net signed area, not total area.
Where Riemann sums are used
Every definite integral is built from them, so they sit behind area between curves, volumes, work and the average value of a function, whose formula is literally the limit of an average of samples. In science and engineering, they turn measured data into totals: distance from velocity readings, energy from power readings, and rainfall from hourly rates.
Riemann sum calculator
Pick a method and \( n \) and compare with the exact integral:
Riemann Sum Approximator
Left, right, midpoint, trapezoid and Simpson sums compared with the exact value.
Want to see the rectangles? Turn on “Riemann rectangles” in the visual lab and drag the \( n \) slider. For a full page that lists the approximation, the exact value and the error side by side, use the Riemann sum calculator.
Practice problems
Try these before checking the answers.
- \( L_4 \text{ for } f(x) = x \text{ on } [0, 4] \)
- \( M_2 \text{ for } f(x) = x^2 \text{ on } [0, 2] \)
- \( T_2 \text{ for } f(x) = x^2 \text{ on } [0, 2] \)
- \( R_4 \) for \( f(x) = \frac1x \) on \( [1, 3] \)
- \( S_2 \) for \( f(x) = x^3 \) on \( [0, 2] \)
- Use the trapezoidal rule with the values \( f(0) = 1,\ f(2) = 3,\ f(4) = 4,\ f(6) = 6 \) to estimate \( \int_0^6 f(x)\,dx \).
Answers: (1) \( 6 \); (2) \( 2.5 \); (3) \( 3 \); (4) \( 0.95 \), an underestimate because \( \frac1x \) is decreasing; (5) \( 4 \), which is exact since Simpson’s rule handles cubics perfectly; (6) \( 21 \).
FAQ
Which Riemann sum is most accurate?
Among the rectangle sums, the midpoint rule. Overall, Simpson’s rule is usually best for smooth functions.
Why must n be even for Simpson’s rule?
Each parabola spans two subintervals, so subintervals must come in pairs.
Is the trapezoidal rule a Riemann sum?
Not in the strict sense, since it uses trapezoids rather than rectangles. But it equals the average of the left and right Riemann sums, so it converges to the same integral.
How many rectangles do I need for a good estimate?
It depends on the method and the function. The error bounds above let you solve for \( n \): for the trapezoid rule, choose \( n \) large enough that \( \frac{K(b - a)^3}{12n^2} \) is below your tolerance.
What does a negative Riemann sum mean?
It means more of the estimated signed area lies below the x-axis than above it. The integral, and its Riemann sums, count area below the axis as negative.
Further reading
- The Area Problem (Paul’s Online Math Notes) — left, right and midpoint rectangle estimates worked out step by step
- Approximating Definite Integrals (Paul’s Online Math Notes) — the midpoint, trapezoid and Simpson’s rules with error bound formulas
- Approximating Areas (OpenStax Calculus Volume 1) — sigma notation, sum formulas and Riemann sums in textbook form
Calculators for this topic
Keep learning
Optimization Problems in Calculus: 4 Solved Examples
Solve calculus optimization problems in 6 steps. Worked examples: the largest fenced area, the open box, the cheapest can and the closest point on a curve.
Related Rates: Step-by-Step Strategy and Classic Problems
Solve related rates problems in 6 steps. Worked classics: the sliding ladder, the expanding balloon, the draining cone and the moving shadow.

