Riemann Sum Calculator
Last updated: 7 August 2026
Reviewed by Gavin Meiring, Lead research and primary author ยท Doctoral Candidate (Corporate Governance) ยท Research and drafting assisted by AI
- Riemann sums are named for Bernhard Riemann, whose 1854 thesis defined the integral as the limit of such sums.
- The idea of slicing a region into pieces to measure it โ the 'method of exhaustion' โ was already used by Eudoxus and Archimedes more than two thousand years earlier.
- The midpoint rule is about twice as accurate as the left and right endpoint rules for smooth functions, because its errors tend to cancel out.
Riemann Sum Calculator
The Riemann sum calculator approximates the area under a curve by dividing it into rectangles and summing their areas. It supports left, right, and midpoint methods, making it a valuable tool for calculus students learning integration and for anyone needing numerical area estimates. Enter your function, interval, number of subintervals, and method to get your result.
How to Use the Riemann Sum Calculator
- Enter your function f(x) in the Riemann Sum Calculator input field. Set the lower bound a and upper bound b of your interval.
- Choose the number of subintervals n. More subintervals give greater accuracy.
- Select your method: left endpoint, right endpoint, or midpoint.
- Click Calculate to see the Riemann sum and, optionally, a table of rectangle values.
The Formula
For n subintervals of equal width over [a, b]:
Width of each subinterval: delta_x = (b - a) / n
Left Riemann Sum: Sum of f(a + i * delta_x) * delta_x for i = 0 to n-1 Right Riemann Sum: Sum of f(a + i * delta_x) * delta_x for i = 1 to n Midpoint Riemann Sum: Sum of f(a + (i - 0.5) * delta_x) * delta_x for i = 1 to n
Each method chooses a different x value within each subinterval as the height of the rectangle. As n approaches infinity, all three converge to the definite integral.
Real-World Example
Approximate the area under f(x) = x^2 on [0, 2] using 4 subintervals with the midpoint method.
- delta_x = (2 - 0) / 4 = 0.5
- Midpoints: x = 0.25, 0.75, 1.25, 1.75
- f(0.25) = 0.0625, f(0.75) = 0.5625, f(1.25) = 1.5625, f(1.75) = 3.0625
- Sum = 0.5 * (0.0625 + 0.5625 + 1.5625 + 3.0625) = 0.5 * 5.25 = 2.625
The true value of the definite integral is 8/3 = 2.6667. With only 4 subintervals, the midpoint estimate of 2.625 is already very close.
Choosing Between Left, Right, and Midpoint Methods
For an increasing function, the left endpoint method underestimates and the right endpoint method overestimates. For a decreasing function, it is the opposite. The midpoint method is generally the most accurate of the three for a given number of subintervals, because it tends to cancel out the overestimation on one side of each rectangle against the underestimation on the other. If you need high accuracy, use more subintervals or switch to the trapezoidal rule or Simpson's rule, which apply more sophisticated approximation strategies within each subinterval.
Frequently Asked Questions
How many subintervals should I use? More subintervals always improve accuracy. For a rough estimate, 10 to 20 subintervals are often enough. For coursework requiring precision to several decimal places, try 100 or more. The exact integral is the limit as n approaches infinity.
Why does my Riemann sum differ from the definite integral? Riemann sums are approximations. The difference, called the error, decreases as n increases. Functions that curve sharply require more subintervals to achieve a given level of accuracy.
Can Riemann sums give a negative result? Yes. If f(x) is negative over part or all of the interval, the rectangles in that region contribute negative areas. The result reflects the net signed area between the curve and the x-axis.
What is the connection between Riemann sums and integration? The definite integral is formally defined as the limit of a Riemann sum as the number of subintervals approaches infinity and their widths approach zero. Riemann sums are therefore the conceptual foundation of integration.
Four subintervals, and what they cost
The worked example above uses four subintervals on f(x) = x^2 over [0, 2]. With that few rectangles the choice of rule matters more than the count of them. The table holds the function and the interval fixed and reports what each rule returns. The exact value of the integral is 8/3, which is 2.66666667 to eight decimal places.
| Rule | Height of each rectangle | Estimate | Difference from 8/3 |
|---|---|---|---|
| Left endpoint | f at the left edge | 1.75000000 | minus 0.91666667 |
| Right endpoint | f at the right edge | 3.75000000 | plus 1.08333333 |
| Midpoint | f at the centre | 2.62500000 | minus 0.04166667 |
| Trapezoidal | mean of the two edges | 2.75000000 | plus 0.08333333 |
| Simpson's rule | weighted, two panels | 2.66666667 | 0.00000000 |
The left rule sits 0.91666667 below the true area and the right rule 1.08333333 above it. The right error is larger because x^2 climbs steeply, so the right edge of each rectangle stands further above the curve than the left edge stands below it. The two errors do not cancel when you average the rules by hand; they cancel inside the trapezoidal rule, which lands 0.08333333 high.
Simpson's rule returns the exact value on this function with four subintervals. That is not a coincidence. Simpson's rule is exact for every polynomial of degree three or lower, and x^2 is degree two, so the rule has nothing left to approximate. On a function that is not polynomial the rule stops being exact, but it stays far more accurate than the other three for the same number of function evaluations.
Four rectangles behind the worked example
The midpoint method hides its arithmetic behind a sum. Written out, the four rectangles are these.
| Rectangle | x used | Height f(x) | Width | Area |
|---|---|---|---|---|
| 1 | 0.25 | 0.0625 | 0.5 | 0.03125 |
| 2 | 0.75 | 0.5625 | 0.5 | 0.28125 |
| 3 | 1.25 | 1.5625 | 0.5 | 0.78125 |
| 4 | 1.75 | 3.0625 | 0.5 | 1.53125 |
| Sum | 5.25 | 2.625 |
The heights sum to 5.25 and the width is 0.5, so the estimate is 2.625. The first rectangle contributes almost nothing to the total and the last contributes more than half of it, which is the shape of any rapidly increasing curve. If a reader's own answer differs from 2.625, the usual cause is a subinterval width of 0.25 instead of 0.5, which doubles the number of rectangles and halves each width.
Error behaviour as the count rises
Doubling the number of subintervals does not improve every rule at the same rate, and the difference between the rates is the practical reason to prefer one rule over another.
| Subintervals | Midpoint, difference from 8/3 | Trapezoidal, difference from 8/3 |
|---|---|---|
| 4 | 0.04166667 | 0.08333333 |
| 8 | 0.01041667 | 0.02083333 |
| 16 | 0.00260417 | 0.00520833 |
| 32 | 0.00065104 | 0.00130208 |
| 64 | 0.00016276 | 0.00032552 |
| 128 | 0.00004069 | 0.00008138 |
Each doubling of n divides the midpoint error by four and the trapezoidal error by four. The left and right rules improve far more slowly, falling by roughly half with each doubling, so buying accuracy with more rectangles is four times more efficient under the midpoint or trapezoidal rule than under the endpoint rules.
The trapezoidal error is exactly twice the midpoint error at every count, with the opposite sign. Both facts follow from the same relationship: the trapezoidal estimate is the average of the left and right estimates, and the midpoint estimate splits the difference in the other direction.
Two error bounds, and how tight they are
Textbooks give the error of each rule as a bound rather than a value. For the midpoint and trapezoidal rules over an interval of width b minus a with n subintervals, the bound depends on the largest absolute second derivative of the function over that interval, written K.
| Rule | Error bound | Value here, K = 2, width 2, n = 4 |
|---|---|---|
| Trapezoidal | K times (b minus a) cubed, divided by 12 n squared | 0.08333333 |
| Midpoint | K times (b minus a) cubed, divided by 24 n squared | 0.04166667 |
For f(x) = x^2 on [0, 2] the second derivative is the constant 2, so K is 2, and the width is 2. Both bounds come out at exactly the error the table above records, 0.08333333 for the trapezoidal rule and 0.04166667 for the midpoint rule.
That is an unusual case. The bound is attained here because the second derivative is constant across the whole interval, so no part of the interval is easier to approximate than any other. For most functions the second derivative varies, the bound is reached near the steepest part of the curve, and the true error comes out smaller than the bound promises. Read the bound as a ceiling, never as an estimate.
When the curve crosses the axis
The page's FAQ states that a Riemann sum can return a negative value. The deeper point is that it returns a signed total, and a signed total can be zero over a region where nothing is flat.
Take f(x) = x over the interval from minus 1 to 1, with four subintervals. The width of each is 0.5 and the midpoints are minus 0.75, minus 0.25, 0.25 and 0.75. The four heights are the same four numbers, so they cancel in pairs and the midpoint estimate is 0. The exact integral is also 0.
The trapezoidal rule returns 0 as well on this interval, for the same reason. A reader who tests a calculator with a function like this and sees 0 should not conclude the tool is broken. Area below the axis is subtracted from area above it, and the rectangle on the left of this interval contributes exactly the negative of the rectangle mirrored on the right.
Limits of the rectangle method
The Riemann sum is the definition of the integral, and the trapezoidal rule is the cheapest improvement on it. Neither is the end of the story.
For a smooth function with several continuous derivatives, Simpson's rule converges faster still: its error falls with the fourth power of the interval count rather than the second, so doubling n divides the error by sixteen. Its bound depends on the largest absolute fourth derivative rather than the second, which makes it harder to state but much smaller in practice on smooth curves.
For a function with a kink, a jump or a spike, none of the error bounds apply, because the derivatives the bounds assume do not exist across the whole interval. Split the interval at the kink and apply the rule to each piece. This is the detail that separates a numerical answer a reader can defend from one that merely looks precise.
Also try these free tools: