You have a table. It gives you a value at 20 and a value at 30, but the number you actually need is at 24. Linear interpolation is how you fill that gap.
The idea is simple. You pretend the quantity changes at a steady rate between the two rows you have, and you read off the point in the middle. That is not exactly true for most real data, and it is close enough almost every time, because over a small gap nearly anything looks like a straight line.
The quick answer
y = y1 + (x − x1) × (y2 − y1) ÷ (x2 − x1)
x is what you have, y is what you want. Point 1 is the table row below your target, point 2 is the row above it. If you have a table row at 20 giving 12.5 and a row at 30 giving 8.2, and you need the value at 24, that is 12.5 + 4 × (−4.3) ÷ 10 = 10.78.
Or skip the arithmetic and put your two points into the calculator.
What the formula is actually doing
Break it into the two things it does, because then it stops being something to memorise.
First, it works out how far across the gap you are. If your table has rows at 20 and 30 and you need 24, you are 4 units into a 10 unit gap. That is 4 ÷ 10 = 0.4, or 40 percent of the way. Call that fraction t.
Second, it moves that same fraction up the y values. If y goes from 12.5 down to 8.2 across the gap, the total change is −4.3. Forty percent of that change is −1.72. Add it to the starting value and you get 10.78.
That gives you a cleaner way to write the same thing:
t = (x − x1) ÷ (x2 − x1) then y = y1 + t × (y2 − y1)Splitting it in two is worth doing, because t is a built-in error check. It should always land between 0 and 1. If it does not, your target is not actually between your two points, and you have a different problem.
There is one more version you will see, and it is the same maths rearranged:
y = (1 − t) × y1 + t × y2
Read that as a blend. If you are 40 percent of the way across, you take 60 percent of the first value and 40
percent of the second. The two shares always add up to 100 percent. Programmers call this lerp,
and there is more on why the different forms exist in
the formula explained.
Example 1: a temperature sensor table
You are working with a thermistor, a sensor whose resistance changes with temperature. The datasheet only lists values every 10 degrees, and your reading is at 24 °C.
| Temperature (°C) | Resistance (kΩ) |
|---|---|
| 20 | 12.5 |
| 30 | 8.2 |
Step 1. Find the rate of change. Resistance drops from 12.5 to 8.2 over 10 degrees, so:
(8.2 − 12.5) ÷ (30 − 20) = −4.3 ÷ 10 = −0.43 kΩ per °CThe minus sign is telling you resistance falls as temperature rises. That is worth noticing, because if your slope comes out positive here you have swapped something.
Step 2. Find how far past the lower row you are. You need 24, the row below is 20, so you are 4 degrees past it.
Step 3. Move down the line by that much.
12.5 + 4 × (−0.43) = 12.5 − 1.72 = 10.78 kΩStep 4. Does it look right? The answer sits between 8.2 and 12.5, and it is nearer the 12.5 end. That fits, because 24 is nearer 20 than 30. If your answer had come out at 6 or at 14, you would know something went wrong before you used it for anything.
Example 2: a table with awkward numbers
Steam tables tell you the temperature at which water boils at a given pressure. At 100 kPa it boils at 99.61 °C, at 125 kPa it boils at 105.97 °C. Your system runs at 110 kPa.
Step 1. How far across?
t = (110 − 100) ÷ (125 − 100) = 10 ÷ 25 = 0.4Step 2. How much does the value change over the whole gap?
105.97 − 99.61 = 6.36 °CStep 3. Take 40 percent of that change and add it on.
99.61 + 0.4 × 6.36 = 99.61 + 2.544 = 102.15 °CThe real answer is about 102.3 °C. You are out by 0.15 of a degree, which for most work does not matter at all. That gap exists because the real relationship curves slightly, and a straight line cuts the corner. Use wider table rows and that small error gets bigger fast. There is a fuller version of this in interpolating steam tables.
Example 3: working backwards
Sometimes you know the answer and want the input. Back to the thermistor: your meter reads 10.0 kΩ, so what temperature is that?
Nothing new here. You just swap which column you treat as the known one. The fraction now comes from the resistance side:
t = (10.0 − 12.5) ÷ (8.2 − 12.5) = −2.5 ÷ −4.3 = 0.581You are 58.1 percent of the way down the resistance range, so go 58.1 percent along the temperature range:
20 + 0.581 × 10 = 25.81 °CCheck it by going forwards again. At 25.81 degrees you are 5.81 past the lower row, so 12.5 + 5.81 × (−0.43) = 12.5 − 2.498 = 10.00 kΩ. That round trip is the best check you can do, and it takes ten seconds.
One warning. This only works if the values keep moving in the same direction across your gap. If the quantity goes up and then back down between your two rows, there are two possible answers and this method quietly gives you one of them without telling you.
Five mistakes that give wrong answers
1. Using rows that do not surround your target
If your target is outside both points, the formula still hands you a number, but you are now guessing beyond your data rather than filling a gap inside it. That is extrapolation, and it can be wildly wrong without any warning sign. See interpolation vs extrapolation for how quickly it falls apart.
2. Reaching for rows that are further apart than they need to be
If your table has 20, 30 and 40 and you need 24, use 20 and 30. Using 20 and 40 doubles the gap, and doubling the gap roughly quadruples your error. There is no upside to skipping a row you already have.
3. Getting the two columns the wrong way round
The thing you know goes on the bottom of the fraction. This is the easiest slip to make and the hardest to spot, because the answer looks perfectly reasonable. The fix is to write the units next to your numbers as you go. "kΩ per °C" and "°C per kΩ" look obviously different on the page.
4. Rounding too early
Rounding a slope of 0.008333 to 0.008 and then multiplying by a big number throws away real accuracy for no reason. Keep the full number in your calculator and round only the final answer.
5. Interpolating something that does not vary smoothly
The method assumes the quantity slides gradually from one value to the next. It is meaningless for a tax bracket, a shipping band, a product category, or anything that jumps in steps. If a table row means "anything from 5 to 10 kg costs this", then 7 kg costs exactly that, and interpolating between bands invents a price that does not exist.
When to use something else
| Your situation | Use this instead |
|---|---|
| Widely spaced table, data clearly curves | Cubic spline |
| You need a smooth curve, not a zigzag | Cubic spline |
| Only a few points, and you want a formula | Lagrange polynomial |
| Table with values across the top and down the side | Bilinear interpolation |
| Measurements with noise or scatter in them | A line of best fit, not interpolation |
That last row catches people out. Interpolation forces the answer to pass exactly through every point you give it, including any measurement error in those points. If your data is noisy, you do not want a curve that faithfully reproduces the noise. You want a trend line through it, which is a different job.
Doing this at scale
One value by hand takes under a minute. A whole column of values against a lookup table does not, and that is a spreadsheet job. The Excel guide covers the formulas that find the right two rows for you automatically, including the very common mistake of using FORECAST.LINEAR on a whole table when you meant to use just two rows.