Calculus, Linear Algebra & Discrete Math Integrals & Applications of Integration A = ∫ |f(x) − g(x)| dx, split at each intersection

Area Between Two Curves Calculator

Enter two functions and this calculator finds every point where they cross inside your search window, integrates the gap between them on each stretch, and adds the pieces to give the enclosed area. Because it splits at each crossing and takes the absolute value of each piece, regions where the curves swap places are added rather than cancelled — which is the difference between an area and a signed integral. The table names which curve is on top in each sub-region, and the chart shows the two curves across the region it measured.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
First curve f(x)Use ^ for powers, * for multiplication (2*x, 2x and a plain space all work, so x sin(x) is read as a product), and the function names sin, cos, tan, sec, csc, cot, asin, acos, atan, sinh, cosh, tanh, exp, ln, log (base 10), sqrt, cbrt and abs. The constants pi and e are recognised.x^2
Second curve g(x)The other boundary. Enter 0 if you want the area between f and the x axis.2*x
LimitsAutomatic mode integrates from the first crossing to the last; fixed mode uses the two numbers below.Between the outer intersections
Window start / lower limitIn automatic mode this is only the search window; in fixed mode it is the lower limit of integration.-1
Window end / upper limitIn automatic mode this is only the search window; in fixed mode it is the upper limit.3

It returns

  • Enclosed area — The integral of the absolute gap, so sub-regions add instead of cancelling.
  • Signed integral of f − g — Positive where f is on top, negative where g is. It differs from the area whenever the curves swap places.
  • Crossings found in the window
  • Left limit used
  • Right limit used

The formula

A=ab|f(x)g(x)|dx
A=cd|xR(y)xL(y)|dy

In plain text: A = ∫ from a to b of |f(x) − g(x)| dx

  • AArea enclosed between the two curves (units of y times units of x)
  • f, gThe two boundary curves (units of y)
  • a, bLimits of integration, usually the outermost intersections (units of x)

In practice you split the interval at each intersection and integrate the larger minus the smaller on each piece, which is exactly what the absolute value does.

Updated Category Integrals & Applications of Integration Verified against published test cases Reading time 10 min

The idea: stack thin rectangles between the two curves

Slice the region into vertical strips. Each strip has width dx and height equal to the vertical gap between the curves at that x — the upper curve minus the lower one. Multiply, add up, and take the limit. That is the integral ∫(top − bottom) dx, and it is the entire method.

Everything that makes these problems fiddly comes from one question: which curve is on top? The answer can change along the interval, and it changes exactly at the points where the curves cross. So the real work is finding the intersections, and then integrating the correct difference on each stretch between them.

Writing the integrand as |f − g| handles it automatically. The absolute value picks whichever curve is higher without you having to decide, and it guarantees that every strip contributes a positive amount. Compare that with the plain integral ∫(f − g) dx, which lets a stretch where g is on top subtract from a stretch where f is on top. Both quantities are reported here, and the gap between them tells you the curves swapped places.

You do not always want a vertical slice. If the region is bounded left and right rather than above and below — a parabola opening sideways, say — horizontal strips are simpler, and the integral becomes ∫(right − left) dy. The arithmetic is identical with the roles of the variables exchanged.

Finding the limits, which is where most of the difficulty lives

In automatic mode the calculator scans your window at 801 points, watches the sign of f − g, and records every place it flips. Each flip is then refined by 60 rounds of bisection, which locates the crossing to roughly machine precision. Integration then runs from the first crossing to the last, splitting at every crossing in between.

This is a numerical search, and it has the honest limitation that every numerical search has: two crossings closer together than the sample spacing can be missed as a pair. The spacing is the window width divided by 800, so a window of 4 units resolves features down to 0.005. Narrow the window when you suspect crowding.

A crossing that is not a sign change is invisible to a sign-change search, and mostly that is correct. Where f − g touches zero without crossing — against 2x − 1, which meet only at x = 1 — there is no enclosed region on either side to measure, so the region has zero width there. The one case where this costs you something real is a meeting point that sits on the edge of a domain: sqrt(x) and meet at the origin and at 1, but the origin is where sqrt begins rather than where the difference changes sign, so automatic mode reports one crossing and no region. Switch to fixed limits and enter 0 and 1.

Fixed-limit mode exists for the cases where the mathematical answer depends on limits you were given rather than on the geometry: an area swept between two specific times, or a region cut off by a vertical boundary. In that mode the calculator still splits at every interior crossing, so the absolute value is still applied correctly.

Worked example: the area between y = x² and y = 2x

These are the default curves.

  1. Find the intersections. Set x² = 2x, so x² − 2x = 0, so x(x − 2) = 0. The curves meet at x = 0 and x = 2.
  2. Decide which is on top. Test the midpoint x = 1: the line gives 2, the parabola gives 1. The line is above.
  3. Set up the integral. A = ∫ from 0 to 2 of (2x − x²) dx.
  4. Antidifferentiate. x² − x³/3.
  5. Evaluate. At the upper limit, 4 − 8/3 = 4/3. At the lower limit, 0. So A = 4/3 = 1.3333333.

The calculator reports exactly that, with intersections at 0 and 2 and a single sub-region in the table with the note that g(x) — the line, entered second — is on top.

Now a case where the sign matters. Take f = sin x, g = 0, over fixed limits from 0 to 2π. The curves cross at x = π inside the interval. On the first half sine is above the axis and contributes +2; on the second half it is below and contributes −2. The signed integral is therefore 0, while the area is 2 + 2 = 4. That pair of numbers is one of this calculator's test vectors, and it is the single clearest illustration of why the absolute value belongs in the formula.

And a case where the split is essential. For f = x³ against g = x, the curves cross at −1, 0 and 1. The cubic is above the line between −1 and 0 and below it between 0 and 1. Each piece has area 1/4, so the total is 1/2 — but the signed integral over the whole range is zero, since the two pieces are mirror images.

How to read the results

Compare the area against the signed integral. When they match in magnitude, one curve stayed above the other throughout, and the sign of the signed integral tells you which. When the area is larger, the curves swapped places and the table shows where.

Check the crossing count against what you expect. Two polynomials of degrees m and n can cross at most max(m, n) times, so a count higher than that in your window means the search found numerical noise — usually because the two functions are equal on a whole stretch. A count lower than expected means a crossing fell outside the window.

Check the limits the calculator actually used. In automatic mode they are the outermost crossings, which may be inside your window. If they sit exactly at the window edges, the region probably extends beyond it and you should widen the window.

Read the sub-region table when the answer surprises you. Each row is bounded by consecutive crossings, gives that piece's area as a positive number, and names the curve on top. Adding the pieces reproduces the total, which is a useful arithmetic check on any hand calculation.

Standard area-between-curves problems and their exact answers

Every value below is exact and derived from elementary antiderivatives, so it is a fair check on this calculator. Two rows need fixed limits rather than automatic mode — see the note underneath.
CurvesIntersectionsTop curveExact areaDecimal
and 2x0, 2the line4/31.3333333
and x0, 1the line1/60.1666667
and 4−2, 2the constant32/310.666667
and x−1, 0, 1swaps at 01/20.5000000
sin x and 0 on [0, π]0, πthe sine22.0000000
sin x and 0 on [0, 2π]0, π, 2πswaps at π44.0000000
sqrt(x) and 0 (domain edge), 1the root1/30.3333333
e^x and 1 on [0, 1]0the exponentiale − 20.7182818

The x³ against x row and the sine over a full period row both have a signed integral of zero. Their areas are not zero, which is the whole point of the absolute value. Two rows need fixed limits. For sqrt(x) against x² the curves do meet at the origin, but that meeting is the left-hand edge of the domain of sqrt rather than a sign change of f − g, so the automatic scan finds only the crossing at x = 1; enter 0 and 1 as fixed limits. The e^x against 1 row is the same situation at a tangential-looking single contact, which is why the row states its interval.

Mistakes that produce the wrong area

  • Integrating f − g across a crossing without splitting. The two sides cancel and you get a number smaller than the true area, sometimes exactly zero.
  • Subtracting in the wrong order. Bottom minus top gives a negative result. The absolute value fixes it, but if you are working by hand, check which curve is higher at a test point inside each stretch.
  • Missing an intersection outside the window. Automatic mode can only see crossings you gave it room to find. If the region looks clipped, widen the window.
  • Assuming polynomials cross where their formulas look equal. Solve the equation properly. x² = 2x has roots 0 and 2, not just 2 — dividing both sides by x loses the root at the origin.
  • Slicing the wrong way. Some regions need horizontal strips because a single vertical strip would cross three boundary pieces. Rewrite the curves as functions of y and integrate in y instead.
  • Treating a tangential touch as a boundary. Where two curves touch without crossing there is no enclosed region on either side of that point, and the width of the region is zero there.

Where this leads next

Rotate the region and you get a volume. Spinning the area between two curves about a horizontal axis gives washers of outer radius f and inner radius g, and the volume is π∫(f² − g²) dx — handled by the disk and washer calculator. Rotating about a vertical axis instead favours the shell method.

Consumer and producer surplus are areas between curves. In economics, the area between a demand curve and the market price is consumer surplus, and the area between price and the supply curve is producer surplus. Both are computed by the integral on this page with the price line as one of the two curves.

The area between two cumulative distributions is a standard measure of how far apart two probability models are, and it is the same integral again.

For a single curve against the axis, enter 0 as the second function, or use the definite integral calculator directly and read its unsigned-area output.

For the length of the boundary rather than the area it encloses, use the arc length calculator, which integrates sqrt(1 + f′²) instead.

Frequently asked questions

Do I have to find the intersection points myself?

No. In automatic mode the calculator scans your window for sign changes of f − g and refines each one by bisection, then integrates from the first crossing to the last. You only need to supply a window wide enough to contain the region, and the results report which limits it actually used.

Why is the area different from the integral of f minus g?

Because the plain integral is signed and lets stretches where g is on top subtract from stretches where f is on top. Area never does that. For sine against the axis over a full period the signed integral is 0 while the area is 4, and the calculator reports both so the difference is visible.

How do I get the area between a curve and the x axis?

Enter 0 as the second function. Everything else works the same way: crossings of the curve with the axis become the split points, and each piece is measured as a positive area. That is how the sine examples in the reference table are computed.

When should I integrate with respect to y instead?

When a vertical strip would cross more than two boundary pieces — typically a region bounded on the left and right by different curves, such as the area inside a sideways parabola. Rewrite both boundaries as functions of y, then integrate right − left over the range of y. This calculator works in x, so you would swap the roles by hand before entering them.

What if the curves never cross?

Then no region is enclosed, and automatic mode says so rather than inventing limits. Switch to fixed limits and choose the range you actually want; one curve stays above the other throughout, so the area is a single piece and equals the absolute value of the signed integral.

How accurate is the result?

Each sub-region is integrated by adaptive Simpson quadrature to a tolerance of 1e−11, and the crossings are located by 60 bisection steps, so on a smooth pair of curves you can expect eight or more correct digits. Accuracy degrades where a curve has a vertical tangent or a singularity at a boundary of the region.

Can it handle more than two crossings?

Yes. Every crossing inside the integration range becomes a split point, and each resulting piece appears as its own row in the table with its own area and top curve. against x is the standard three-crossing example, and the two pieces each have area 1/4.

Why does my answer come out negative in a textbook solution?

Because the textbook set up ∫(f − g) with the lower curve first. An area is never negative; a negative result simply means the subtraction ran the wrong way round. Swap the two functions, or take the absolute value, and the magnitude is the same.

References

  • Calculus, 8th edition (areas between curves, section 6.1) — James Stewart, Cengage Learning
  • Thomas' Calculus, 14th edition (applications of definite integrals, chapter 6) — Hass, Heil & Weir, Pearson
  • Numerical Recipes: The Art of Scientific Computing, 3rd edition (quadrature and root bracketing) — Press, Teukolsky, Vetterling & Flannery, Cambridge University Press