Solved.tools: Free Online Calculators & Tools

We use cookies for analytics and advertising. Learn more about our cookie policy

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

Was this helpful?


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

  1. Enter your function f(x) in the Riemann Sum Calculator input field. Set the lower bound a and upper bound b of your interval.
  2. Choose the number of subintervals n. More subintervals give greater accuracy.
  3. Select your method: left endpoint, right endpoint, or midpoint.
  4. 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.

  1. delta_x = (2 - 0) / 4 = 0.5
  2. Midpoints: x = 0.25, 0.75, 1.25, 1.75
  3. f(0.25) = 0.0625, f(0.75) = 0.5625, f(1.25) = 1.5625, f(1.75) = 3.0625
  4. 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.

RuleHeight of each rectangleEstimateDifference from 8/3
Left endpointf at the left edge1.75000000minus 0.91666667
Right endpointf at the right edge3.75000000plus 1.08333333
Midpointf at the centre2.62500000minus 0.04166667
Trapezoidalmean of the two edges2.75000000plus 0.08333333
Simpson's ruleweighted, two panels2.666666670.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.

Rectanglex usedHeight f(x)WidthArea
10.250.06250.50.03125
20.750.56250.50.28125
31.251.56250.50.78125
41.753.06250.51.53125
Sum5.252.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.

SubintervalsMidpoint, difference from 8/3Trapezoidal, difference from 8/3
40.041666670.08333333
80.010416670.02083333
160.002604170.00520833
320.000651040.00130208
640.000162760.00032552
1280.000040690.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.

RuleError boundValue here, K = 2, width 2, n = 4
TrapezoidalK times (b minus a) cubed, divided by 12 n squared0.08333333
MidpointK times (b minus a) cubed, divided by 24 n squared0.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: