Linear Interpolation Calculator
Linear interpolation estimates a value between two known points by drawing a straight line between them. Between (2, 10) and (6, 30), x = 4 is halfway along, so y = 10 + (4 − 2) × 5 = 20 (see the steps). Type a y instead to find its x, or paste a whole table.
Find a value between two points
Type two known points and an x to get its y, or a y to get its x. The answer updates as you type.
Paste both points at once, such as (2, 10), (6, 30), into any box.
One x, y pair per line. Paste two columns from Excel or Sheets; a header row is skipped and rows are sorted by x.
Type x to get y, or type y to get x. Several values work too: 3, 4.5, 5.
Check your input
On the line
How to Use This Calculator
-
Enter what you know
Type two points, or switch to Table and paste x, y rows from a spreadsheet.
-
Type x or y
Type the x you need a y for. Or type a y, and the calculator finds the x.
-
Read the answer
You get the exact value with the working, the line on a graph and the Excel formula.
What is linear interpolation?
Linear interpolation is a way to fill in a missing value between two values you already know. You treat the two known points as the ends of a straight line and read the answer off that line. If a quantity is 10 at x = 2 and 30 at x = 6, then at x = 4, halfway between, linear interpolation gives 20, halfway between 10 and 30.
You need it whenever data comes in steps: a table lists values at 20 °C and 30 °C but you need 24 °C, or a report gives sales for each year and you want a figure from partway through one. The straight line is an assumption, so the answer is an estimate, but over a short gap it is usually a close one.
The linear interpolation formula
- (x1, y1) and (x2, y2) are the two points you know.
- x is the value you have, and y is the value you want.
- (y2 − y1) ÷ (x2 − x1) is the slope: how much y changes for each step of 1 in x.
- t says how far along you are, from 0 at the first point to 1 at the second. At t = 0.5 you are halfway.
How to do linear interpolation, step by step
- Pick the two known points on either side of your x.
- Find the slope: the change in y divided by the change in x.
- Find how far your x is from the first point: x − x1.
- Multiply the slope by that distance and add y1.
Say a table gives a pressure of 1.2 bar at 20 °C and 1.8 bar at 30 °C, and you need it at 24 °C. The slope is (1.8 − 1.2) ÷ (30 − 20) = 0.06 bar per degree. 24 °C is 4 degrees past 20 °C, so the pressure rises by 4 × 0.06 = 0.24 bar, and y = 1.2 + 0.24 = 1.44 bar.
The t form gets there the same way. t = (24 − 20) ÷ (30 − 20) = 0.4, so 24 °C is 40% of the way from 20 °C to 30 °C, and the pressure is 40% of the way from 1.2 to 1.8: 1.2 + 0.4 × 0.6 = 1.44.
Finding x when you know y
Sometimes the question runs the other way: at what temperature does the pressure reach 1.5 bar? Swap the roles of x and y in the formula:
Here x = 20 + (1.5 − 1.2) × (30 − 20) ÷ (1.8 − 1.2) = 20 + 0.3 × 10 ÷ 0.6 = 25 °C. This is called inverse interpolation. It only works when y₁ and y₂ differ; on a flat line every x gives the same y. In the calculator, type the y and the x field fills in as the answer.
Interpolation vs extrapolation
Both use the same formula. The difference is where your x sits.
| Interpolation | Extrapolation | |
|---|---|---|
| Where x is | Between the known points | Before the first point or past the last |
| Value of t | 0 to 1 | below 0 or above 1 |
| Example, (2, 10) and (6, 30) | x = 4 gives 20 | x = 8 gives 40 |
| How far to trust it | Usually close, if the gap is small | Only as far as the trend really holds |
Extrapolation assumes the straight line keeps going where you have no data. A short step past the last point is often fine. A long one can be badly wrong: a child's height grows almost in a straight line from age 4 to 10, but carrying that line on to age 40 gives a giant. The calculator answers either way and says in words when your value is outside the points.
Interpolating in a table
With a whole table you do not draw one line from the first row to the last. You find the two rows on either side of your x and interpolate between those two only. Joining every pair of neighboring rows this way is called piecewise linear interpolation, and it follows the data much more closely than a single line would.
| Year (x) | Revenue (y) |
|---|---|
| 2019 | $120,000 |
| 2020 | $145,000 |
| 2021 | $172,000 |
| 2022 | $198,000 |
| 2023 | $231,000 |
| 2024 | $260,000 |
To estimate revenue at 2021.75, three quarters of the way from 2021 to 2022, use only those two rows: 172,000 + 0.75 × (198,000 − 172,000) = $191,500. Paste the table into the Table mode and the calculator finds the right pair of rows for each x, even when the rows are not in order.
Show the revenue table in the calculator
Double interpolation
Some tables, such as steam tables in engineering, depend on two inputs at once, and the value you need falls between rows and between columns. That takes double (bilinear) interpolation: three ordinary interpolations in a row.
| x = 10 | x = 14 | x = 20 | |
|---|---|---|---|
| z = 100 | 4 | 4.8 | 6 |
| z = 150 | 7.2 | ||
| z = 200 | 8 | 9.6 | 12 |
- Along the z = 100 row, interpolate to x = 14: 4 + 0.4 × (6 − 4) = 4.8.
- Along the z = 200 row, do the same: 8 + 0.4 × (12 − 8) = 9.6.
- Interpolate between those two results to z = 150: 4.8 + 0.5 × (9.6 − 4.8) = 7.2.
You can run each of the three steps through this calculator as a two-point problem. Doing the columns first and the rows second gives the same answer.
Show the last step in the calculator
Linear interpolation in Excel and Google Sheets
FORECAST.LINEAR(x, known_ys, known_xs) draws a line through the points you give it and returns the y at x. Give it exactly two points and that line is the interpolation line:
The first line returns 1.44. The second is the formula typed out, with the two known points in A2:B3 and your x in E2. Older versions of Excel name the function FORECAST, with the same arguments.
For a long table sorted by x, MATCH can find the right pair of rows for you. With x values in A2:A20, y values in B2:B20 and your x in E2:
MATCH finds the last row at or below your x, and OFFSET takes that row and the one after it. It works for any x from the first row up to, but not including, the last. One common mistake is to give FORECAST, TREND or a chart trendline the whole table: they then fit a single best-fit line through every row, which is regression, not interpolation, and it will not pass through your data points.
Lerp and linear interpolation in Python
In programming, linear interpolation is usually called lerp and written with t instead of x:
Lerp moves from a at t = 0 to b at t = 1. Games use it to slide a camera or fade a color, raising t a little every frame. Many engines clamp t to the range 0 to 1, so lerp never overshoots; Unity's Mathf.Lerp does this, and Mathf.LerpUnclamped does not.
NumPy's np.interp(x, xp, fp) does piecewise linear interpolation over a whole table in one call. The xp values must be in increasing order. Outside the table it does not extrapolate: it returns the first or last y value instead, so an x past the end gives a flat answer.
How accurate is linear interpolation?
It is exact when the data really lies on a straight line, such as a price per kilogram or a constant speed. When the data curves, the straight line cuts the corner and the estimate is off. The error shrinks fast as the gap gets smaller: halve the distance between the known points and the error drops to about a quarter. Here is y = x² at the middle of three gaps:
| Known points at x = | Middle x | Line gives | True x² | Error |
|---|---|---|---|---|
| 2 and 3 | 2.5 | 6.5 | 6.25 | 0.25 |
| 2.25 and 2.75 | 2.5 | 6.3125 | 6.25 | 0.0625 |
| 2.4 and 2.6 | 2.5 | 6.26 | 6.25 | 0.01 |
So if your table has wide gaps and the values clearly bend, expect the estimate to be off, and check whether the source gives a finer table. For smooth curves through many points, a spline or a polynomial (Lagrange) fit can do better, but for reading a value from a table, linear interpolation is the standard method. When the y values change at a steady rate, our rate of change calculator gives the slope on its own, and the proportion calculator handles lines that pass through 0.
Frequently Asked Questions
What is linear interpolation?
Linear interpolation is a way to estimate a value between two known points by assuming a straight line joins them. If a table gives 10 at x = 2 and 30 at x = 6, linear interpolation says the value at x = 4, halfway along, is 20, halfway between 10 and 30.
What is the linear interpolation formula?
y = y₁ + (x − x₁) × (y₂ − y₁) ÷ (x₂ − x₁), where (x₁, y₁) and (x₂, y₂) are the known points and x is the value you want a y for. The fraction (y₂ − y₁) ÷ (x₂ − x₁) is the slope of the line through the two points.
How do you do linear interpolation step by step?
Work out the slope between the two known points, multiply it by how far your x is from x₁, and add the result to y₁. With (20, 1.2) and (30, 1.8) at x = 24: the slope is 0.6 ÷ 10 = 0.06, the distance is 4, and y = 1.2 + 4 × 0.06 = 1.44.
How do you find x with linear interpolation?
Swap the roles of x and y: x = x₁ + (y − y₁) × (x₂ − x₁) ÷ (y₂ − y₁). With (20, 1.2) and (30, 1.8), the x where y = 1.5 is 20 + 0.3 × 10 ÷ 0.6 = 25. In this calculator, type the y and leave x empty.
How do you do linear interpolation in Excel?
Use =FORECAST.LINEAR(x, known_ys, known_xs) with just the two rows around your x. For x = 24 between (20, 1.2) and (30, 1.8), =FORECAST.LINEAR(24, {1.2,1.8}, {20,30}) returns 1.44. Do not give it the whole table, because then it fits one trend line through every row instead of interpolating.
What is the difference between interpolation and extrapolation?
Interpolation estimates a value between the known points; extrapolation carries the line on past them. Both use the same formula, but extrapolation is riskier, because nothing in the data shows that the straight line keeps going.
What does lerp mean?
Lerp is short for linear interpolation, written as lerp(a, b, t) = a + t × (b − a). It returns a when t = 0, b when t = 1, and the value in between for any t from 0 to 1, which is how games and animation software move smoothly from one value to another.