To interpolate between two values, you use a simple formula: multiply the starting value by (1 – t) and add the ending value multiplied by t, where t is a number between 0 and 1 representing how far between the two values you want to go. At t = 0 you get the starting value, at t = 1 you get the ending value, and anything in between gives you a proportional point along the way. This technique, called linear interpolation (often shortened to “lerp”), is one of the most widely used operations in math, programming, and data analysis.
The Linear Interpolation Formula
The core formula looks like this:
result = (1 – t) × A + t × B
A is your starting value, B is your ending value, and t controls where you land between them. If A is 10 and B is 30, setting t to 0.5 gives you 20 (the midpoint). Setting t to 0.25 gives you 15 (one quarter of the way). Setting t to 0.75 gives you 25 (three quarters of the way).
You can also write the formula as A + t × (B – A), which is mathematically equivalent and sometimes easier to think about. This version says: start at A, then move t percent of the distance toward B.
The formula works for any pair of numbers: temperatures, prices, pixel colors, coordinates, or sensor readings. It also extends naturally to pairs of 2D or 3D points, where you apply the same formula to each coordinate independently.
A Step-by-Step Example
Say you know the temperature was 60°F at 2:00 PM and 80°F at 4:00 PM, and you want to estimate the temperature at 3:00 PM. First, figure out t: 3:00 PM is halfway between 2:00 and 4:00, so t = 0.5. Then plug in:
result = (1 – 0.5) × 60 + 0.5 × 80 = 30 + 40 = 70°F
What about 2:45 PM? That’s 45 minutes into a 120-minute window, so t = 45/120 = 0.375. The result: (1 – 0.375) × 60 + 0.375 × 80 = 37.5 + 30 = 67.5°F.
The general pattern for finding t when you have a known position x between two reference points x₀ and x₁ is: t = (x – x₀) / (x₁ – x₀). This converts your position into the 0-to-1 range the formula expects.
Interpolation in Excel
Excel doesn’t have a dedicated “LERP” function, but you can build the formula directly in a cell. If your starting value is in A1 and your ending value is in B1, and your t value is in C1, enter:
=(1-C1)*A1 + C1*B1
For more complex scenarios where you have a table of known x-y pairs and want to predict a value, Excel’s FORECAST.LINEAR function fits a regression line through your data. Its syntax is FORECAST.LINEAR(x, known_y’s, known_x’s), where x is the point you want to estimate. This works well when you have more than two data points and want a best-fit prediction rather than exact interpolation between two neighbors.
Interpolation in Python
Python offers several tools depending on your needs. For a quick one-off calculation, just write the formula directly:
result = (1 – t) * a + t * b
NumPy’s interp function handles cases where you have arrays of known data points and want to interpolate at specific positions. You pass it the x-coordinates where you want values, plus the x and y coordinates of your known data, and it performs linear interpolation automatically.
For more flexibility, SciPy’s interpolation tools let you choose between linear, quadratic, cubic, and other methods. The default behavior is linear interpolation, but switching to cubic gives you smoother curves between points. SciPy’s newer interpolation functions have replaced the older interp1d class, so check the current documentation for the recommended approach.
If you’re working with tabular data in pandas, the DataFrame.interpolate() method fills in missing values using linear interpolation by default. For time series data with irregular spacing, setting method="time" makes the interpolation respect the actual time gaps between entries rather than treating each row as equally spaced. Pandas also offers simpler gap-filling strategies like forward fill (carrying the last known value forward) and backward fill, which aren’t true interpolation but solve similar problems.
Interpolation in Game Engines
Game engines like Unity provide a built-in Lerp function that takes three arguments: the start value, the end value, and t. One important detail: Unity’s Mathf.Lerp clamps t to the 0-to-1 range automatically. If you pass in t = 1.5, it treats it as t = 1 and returns the end value. This prevents overshooting, which is useful for animation but can be surprising if you intentionally want to extrapolate beyond your endpoints. Some engines offer an “unclamped” variant for that purpose.
Lerp is everywhere in game development: smoothing camera movement, blending colors, fading audio, animating UI elements, and transitioning between character poses. The key pattern is calling lerp repeatedly each frame with a small t value to create smooth, gradual movement toward a target.
When Linear Interpolation Falls Short
Linear interpolation assumes a straight-line relationship between your two values. That’s perfectly fine for many situations, but it creates visible corners when you chain together multiple interpolated segments. If you’re drawing a curve through several data points, the transitions at each point will look sharp rather than smooth.
Cubic spline interpolation solves this by fitting smooth curves through your points. It produces results that are more accurate when the underlying data follows a curve, and it eliminates the sharp transitions. The tradeoff is that cubic interpolation can “overshoot,” producing values outside the range of your original data. If all your known values are positive, a cubic interpolation might briefly dip negative between them. Linear interpolation never does this, since it stays strictly between the two endpoint values.
For most everyday calculations where you just need a reasonable estimate between two known values, linear interpolation is the right choice. It’s fast, predictable, and easy to verify by hand.
Interpolating in Two and Three Dimensions
When your data lives on a 2D grid rather than a single line, you need bilinear interpolation. The idea is to perform linear interpolation three times: once along one axis using two pairs of neighboring values, then once more to blend those intermediate results along the other axis. The final value is a weighted average of the four nearest grid points, with the weights determined by how close your target position is to each one.
This extends naturally to three dimensions as trilinear interpolation, which uses eight surrounding points and performs seven linear interpolations. Both methods are widely used in image processing (resizing photos, rotating images, mapping textures onto 3D objects) because they produce smooth results with minimal computation. When an image transformation maps a pixel to a fractional position between source pixels, bilinear interpolation estimates the color by blending the four nearest neighbors. Positions that fall outside the image boundaries typically get assigned a default value like black.

