Skip to main content
CalcMax

Linear Interpolation Calculator

Range: -1,000,000 – 1,000,000

Range: -1,000,000 – 1,000,000

Range: -1,000,000 – 1,000,000

Range: -1,000,000 – 1,000,000

Range: -1,000,000 – 1,000,000

Result

5.000000

Interpolated y

Slope
3.000000
Position along the segment
0.500000

A linear interpolation calculator finds the y value that sits on the straight line between two known points. Give both points and the x you want, and the interpolated y comes back with the slope of that line and the position along it, expressed as a segment fraction between 0 and 1. The default pair is (1, 2) and (3, 8) with x at 2, which lands exactly halfway and gives y equal to 5. Interpolating means reading a value off a line you have already drawn through two measurements, so the answer is only as good as the assumption that the line is straight. When the x you ask for falls outside the two points, the same formula runs on and produces an extrapolation; that is allowed here and is reported rather than refused.

Five positions across the interval from (1, 2) to (3, 8)

xty
102
1.50.253.5
20.55
2.50.756.5
318

The five sample positions are the two ends plus three points that divide the interval into equal parts, so the middle column reads 0, 0.25, 0.5, 0.75 and 1. Reading it downwards is the point of the table: the y column steps by the same amount every time, because a straight line is exactly the case where equal steps in position give equal steps in value. The ends are included so that the first and last rows can be checked against the two known points without any arithmetic. Every cell is a number, so the table is identical in all ten languages the site serves.

Formula

y = y₁ + (x − x₁) × (y₂ − y₁) ÷ (x₂ − x₁) t = (x − x₁) ÷ (x₂ − x₁) y = (1 − t)·y₁ + t·y₂

x₁, y₁
The first known point. It anchors the line: at x equal to x₁ the formula returns y₁ exactly, because the whole distance term collapses to nothing. Setting x₁ equal to 0 is allowed and common, since it makes the point sit on the y axis.
x₂, y₂
The second known point. The two points together fix the line, which is all a straight line needs. Their x values must differ: two points with the same x describe a vertical line where one x maps to every y at once, and no single answer exists.
x
The position you want a value at. It need not lie between the two points — outside that range the same expression keeps going and the result is an extrapolation rather than an interpolation, which is why the reading is reported rather than restricted.
t
The segment fraction: how far along the line the point sits, counted from the first point. It is 0 at the first point, 0.5 halfway and 1 at the second, and it is the weight the two y values are mixed in — the section of the line, in the sense of the ratio the point divides it in.

Reach for this when two measurements are known and a value in between is wanted: a reading between two table entries, a value at a date between two observations, or any pair of quantities assumed to move together in a straight line. When the two points exist to measure steepness instead, that is the slope of a line; when the wanted value is exactly halfway, it is the midpoint.

Worked examples

  1. Halfway between (1, 2) and (3, 8)

    1. The change in y is 8 − 2 = 6, and the change in x is 3 − 1 = 2
    2. The line rises 3 in y for every 1 in x, so the slope is 3
    3. x = 2 sits 1 unit along a 2-unit interval, so the segment fraction is 1 ÷ 2 = 0.5
    4. Mix the two values in that proportion: (1 − 0.5) × 2 + 0.5 × 8 = 1 + 4 = 5
    5. The interpolated value is y = 5

    The default case, and the one worth reading twice: at a fraction of one half the answer is the plain average of the two y values, 2 and 8. That is a coincidence of landing dead centre, not a rule — a quarter of the way along the answer would be 3.5 instead.

  2. A line that falls

    1. The change in y is −20 − 0 = −20, and the change in x is 10 − 0 = 10
    2. The slope is −20 ÷ 10 = −2, so the line falls two units for every one across
    3. x = 4 is 4 units along a 10-unit interval, so the segment fraction is 0.4
    4. Mix: 0.6 × 0 + 0.4 × (−20) = −8
    5. The interpolated value is y = −8

    Both ends of this one are signed, which is what makes it worth checking by hand: the run is 10 rather than −10, and the answer lands between the two known values rather than beyond them. Reading the interval backwards would flip the slope and the fraction together while leaving y correct, which is exactly why the fraction is printed beside the answer.

  3. Asking past the last point

    1. The same line as the first example: a rise of 3 for every 1 across
    2. x = 4 is 3 units along a 2-unit interval, so the segment fraction is 3 ÷ 2 = 1.5
    3. The fraction is above 1, which is how the answer says the point lies beyond the second known value
    4. Mix: (1 − 1.5) × 2 + 1.5 × 8 = −1 + 12 = 11
    5. The value is y = 11

    Extrapolation, and the reason the position is printed as a plain number instead of being clamped to the interval. A fraction of 1.5 says the point sits half a segment past the far end; the arithmetic is identical to interpolation, and only the interpretation changes.

Limitations

The two known points must have different x values. Two points stacked at the same x describe a vertical line, where one x corresponds to infinitely many y values and no single interpolated answer exists — so that input is refused instead of returning infinity. All five numbers are limited to a magnitude of one million, since the slope and the fraction are both quotients that the panel rounds to six decimals and the round trip stops being checkable beyond that. Values outside the interval are accepted and reported rather than refused: the position comes back above 1 or below 0, which is the page telling you it has extrapolated. What the page cannot tell you is whether extrapolating was sensible — a straight line through two points says nothing about what happens past them, and no confidence figure is printed, because two points cannot support one.

Frequently asked questions

What is linear interpolation?
Drawing a straight line through two known points and reading the value at a position between them. The word linear says the assumption out loud: the quantity is taken to change at a steady rate across the interval, so the answer is a weighted mix of the two known values rather than a measurement.
What does the segment fraction tell me?
How far along the line the point sits, counted from the first known point. It is 0 at the first, 0.5 halfway and 1 at the second. The value itself can be written as the two known y values mixed in those proportions, so the fraction is the whole of what interpolation adds to the two points.
Can I interpolate outside the two points?
You can, and this page does — but the operation is then an extrapolation, and the position comes back above 1 or below 0 to say so. A straight line through two points is a guess about the interval between them; extended past either end it is a much stronger guess about something the data never covered.
Why is a vertical pair of points refused?
Because there is no single answer to give. Two points with the same x sit one above the other, and the line through them assigns every y value at once to that one x. The page refuses that input by name rather than returning an infinity, which would look like an answer.
Does the order of the two points matter?
Not for the value read off the line, but it does change the slope and the position. Swapping the two points flips the sign of both the slope and the segment fraction while leaving the interpolated y where it was, since the same line is being described in the other direction.
Why is no confidence figure printed?
Because two points cannot support one. A fit measured against two points is perfect by construction, so any quality-of-fit number would come out at its best value every time, whatever the underlying data actually do. What the page prints instead is the slope and the position, which are facts about the line rather than claims about the data.

References

Related calculators