CCalclabhub

Algebra

How To Calculate Linear Interpolation

Linear interpolation fills the gaps between two points you already know. Work out how far along the gap your target sits, then walk the same fraction along the values.

Quick Answer

y = y1 + (x - x1) x (y2 - y1) / (x2 - x1)

(x1, y1)
The lower known point
(x2, y2)
The upper known point
x
The input you want a value for
y
The interpolated result

Find the fraction of the way your target x sits between the two known x values, multiply that fraction by the gap between the two y values, and add it to the first y. At x = 25 between (0, 0) and (100, 200) the answer is 50.

What Is Linear Interpolation?

Linear interpolation estimates a value inside the range of two known points by assuming the line between them is straight. It is the arithmetic behind reading between the rows of a table.

The idea is a fraction. Work out where your target sits between the two known inputs, then move the same fraction of the way between the two known outputs. A quarter of the way across gives a quarter of the way up.

Written as a slope, the formula says the change in y is the slope times the change in x. That is nothing more than the equation of a straight line rearranged, and it is why interpolation and slope are the same calculation seen from two sides.

Written as a weighted average, the same formula blends the two known values. The weights are the distances to the opposite end, so a target sitting close to the left point takes almost all of its value from the left point.

It is used constantly with tables. Steam tables, tax brackets, load charts, mortality tables and printed log tables all list values at intervals, and interpolation recovers the values in between.

Engineers use it to calibrate sensors. A probe reads 0 at the low calibration point and 200 at the high point, and every reading in between is converted by interpolating against those two anchors.

Spreadsheets use it for forecasting. Fill a column of months with known values at January and December and the months between follow a straight line, which is usually good enough for a budget.

The assumption is the whole risk. Interpolation is only as good as the claim that the curve is straight between the two points, so the closer together the known points are, the safer the estimate.

Going outside the range is extrapolation, a different and far less reliable operation. Between two points you are reading a gap; beyond them you are guessing at a trend you have no evidence for.

Interpolation always lands between the two known values. That boundedness is what makes it safe: the answer can never be more extreme than the data you started from.

The same formula inverted solves for x given a y. Swap the roles of the two axes and the arithmetic is identical, which is how inverse lookup tables work.

With more than two points the method is applied piecewise. You find the bracketing pair and interpolate within it, which turns a jagged table into a continuous curve made of straight segments.

Units matter on both axes. If x is measured in minutes and y in degrees, the slope carries degrees per minute, and mixing units between the two axes silently scales the answer.

When the two known x values are equal there is no gap to interpolate across, and the formula divides by zero. In practice that means the table has a duplicate row that needs fixing.

A quick check is the endpoints. Put x equal to x1 and the formula must return y1; put x equal to x2 and it must return y2. If either fails, the substitution went in wrong.

Formula

y = y1 + (x - x1) x (y2 - y1) / (x2 - x1)

Formula page →

Walk along the line from the first point using the slope between the two known points.

SymbolMeaning
yInterpolated value
xTarget input
x1, y1Lower point
x2, y2Upper point

y = y1 x (1 - t) + y2 x t, where t = (x - x1) / (x2 - x1)

Formula page →

The same result written as a weighted average of the two known values.

SymbolMeaning
tFraction of the way
yInterpolated value
y1, y2Known values

x = x1 + (y - y1) x (x2 - x1) / (y2 - y1)

Formula page →

Swap the axes to find the input that produces a target value.

SymbolMeaning
xInterpolated input
yTarget value
x1, y1Lower point
x2, y2Upper point

How To Calculate Linear Interpolation

  1. 1

    Identify the two points that bracket your target

    You need one known point below the target and one above it. With points at (0, 0) and (100, 200), a target of 25 sits inside that range, so the pair is the right one to use.

  2. 2

    Work out the fraction of the way

    Subtract the lower x from the target and divide by the span. That is (25 - 0) / (100 - 0), which is 0.25, so the target sits a quarter of the way along.

  3. 3

    Multiply the fraction by the gap in y

    The two known values differ by 200. A quarter of 200 is 50, which is how much the answer rises above the first known value.

  4. 4

    Add it to the first value

    0 plus 50 is 50. The interpolated value at x = 25 is 50, and the sanity check holds because the slope of 2 times 25 gives the same 50.

Examples

Example 1: A sensor calibrated at 0 and 200, read at input 25

First x
0
First y
0
Second x
100
Second y
200
Target x
25
StepCalculationResult
Span of the inputs100 - 0100
Fraction of the way(25 - 0) / 1000.25
Gap between the outputs200 - 0200
Interpolated reading0 + 0.25 x 20050

Result: A target of 25 sits 0.25 of the way from 0 to 100, so the reading is 0.25 of the 200 unit span above zero, which is 50, and the slope of the calibration line is 2, so 2 times 25 confirms the same reading.

Example 2: Temperature at 3:30 pm from readings at 2 pm and 6 pm

First x
14
First y
18
Second x
18
Second y
26
Target x
15.5
StepCalculationResult
Elapsed hours since the first reading15.5 - 141.5
Fraction of the four hour gap1.5 / 40.375
Rise over the whole gap26 - 188
Temperature at 3:30 pm18 + 0.375 x 821

Result: Half past three is 1.5 hours into a 4 hour gap, a fraction of 0.375. The temperature rises 8 degrees across the gap, so 0.375 of that is 3, and the reading at 3:30 pm is 21 degrees.

Calculator

Interpolated value

50

Fraction of the way
25.00%
Slope between the points
2
Span between the inputs
100
Span between the values
200

Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.

Prefer a full-width tool? Open the Linear Interpolation calculator page.

Common Mistakes

  • Interpolating outside the two known points

    That is extrapolation, not interpolation. The straight line has no support beyond the data, and errors grow quickly the further you go.

  • Subtracting the points in the wrong order

    Both the numerator and the denominator must run in the same direction. Using (x - x1) over (x1 - x2) flips the sign and pushes the answer the wrong way.

  • Forgetting to subtract the first x

    The distance is x minus x1, not x itself. Using 25 directly against a span of 100 happens to work here only because x1 is zero.

  • Assuming the data is straight when it is curved

    Compounding, drag and saturation all bend a curve. Interpolating across a wide gap on a curved relationship gives an answer that can be badly off in the middle.

  • Picking the wrong pair from a long table

    Use the two rows that bracket the target, not the first two or the nearest two. With a target near the bottom of a table, the top rows are irrelevant.

  • Dividing by zero when the two inputs match

    If x1 equals x2 the span is zero and the slope is undefined. That usually means a duplicated row in the source table rather than a real calculation.

FAQ

What is the linear interpolation formula?

y equals y1 plus the target minus x1, times the gap between the two y values divided by the gap between the two x values.

What is the difference between interpolation and extrapolation?

Interpolation estimates inside the range of known points and always stays between them. Extrapolation goes outside the range and relies on a trend you have not measured.

Can I interpolate when the points are not equally spaced?

Yes. The formula only uses the actual distance between the two points, so uneven spacing is handled automatically by the fraction.

How do I interpolate in reverse, from a value to an input?

Swap the roles of x and y in the same formula. Subtract the lower y, divide by the span in y, and move that fraction along the x axis.

How accurate is linear interpolation?

It is exact when the underlying relationship is straight, and approximate otherwise. Accuracy improves as the gap between the known points shrinks.

Why does my interpolated value never fall outside the known values?

Because the weight on each end stays between zero and one. The result is a blend of the two known values, so it can never be more extreme than either.

References

  1. [1]Wikipedia, Interpolation — https://en.wikipedia.org/wiki/Interpolation
  2. [2]Wikipedia, Extrapolation — https://en.wikipedia.org/wiki/Extrapolation
  3. [3]Wikipedia, Linear equation — https://en.wikipedia.org/wiki/Linear_equation