Cubic Spline Interpolation Calculator
Build smooth piecewise cubic curves through data points with natural, clamped, or not-a-knot boundaries.
Results are calculated automatically as you enter data.
▼ See explanations and tips below ▼
Related Calculators
What Is Cubic Spline Interpolation?
Cubic spline interpolation is a way to draw a smooth curve through a set of known data points. Instead of forcing one large polynomial through every point, it builds a separate cubic polynomial between each neighboring pair of points.
That local approach is the key idea. Each small interval gets its own cubic equation, but the equations are joined so the curve does not have sharp corners at the shared points, called knots. A cubic spline usually matches the data values at every knot and has matching first and second derivatives at the interior knots. In plain language, the curve is continuous, its slope changes smoothly, and its curvature does not jump suddenly in the middle of the data range.
Cubic splines are useful when you know values at several x-coordinates and want a reasonable estimate between them. They are common in numerical analysis, engineering, scientific computing, animation, data visualization, and anywhere a smooth interpolating curve is more useful than straight-line segments.
A cubic spline is an interpolation method, not a regression or smoothing method. It is designed to pass through the supplied points. If the points contain measurement noise, mistakes, or outliers, the spline will usually reflect those issues rather than average them away.
Why Cubic Spline Interpolation Matters
A straight-line interpolation is easy to understand, but it has corners at the data points. Those corners can be unrealistic when the underlying quantity changes smoothly, such as position, temperature, pressure, concentration, motion, or a sampled mathematical function.
A single high-degree polynomial can also pass through all points, but global polynomial interpolation can behave poorly when many points are used, especially with evenly spaced x-values. Small changes in the data may affect the curve far away from where the change happened. Cubic splines avoid much of that problem by using low-degree local pieces.
The result is a practical compromise: the curve is smoother than piecewise linear interpolation while staying local enough to be easier to control than one global polynomial. Boundary conditions then determine how the curve behaves at the two ends, where there are not neighboring points on both sides to determine the shape automatically.
Key Terms to Know
- Interpolation: Estimating values between known data points while passing through the known points.
- Spline: A piecewise polynomial function joined at selected points called knots.
- Cubic polynomial: A polynomial with terms up to the third power, such as \(a + bt + ct^2 + dt^3\).
- Knot: A data point where neighboring spline pieces meet.
- Segment: One interval between two adjacent x-values. A spline with \(n\) valid points has \(n - 1\) segments.
- Boundary condition: An extra rule used at the left and right ends of the spline to make the spline system complete.
- Natural spline: A cubic spline whose endpoint second derivatives are set to zero.
- Clamped spline: A cubic spline whose endpoint slopes are specified directly.
- Not-a-knot spline: A cubic spline that makes the first two pieces behave like one cubic at the first interior knot and the last two pieces behave like one cubic at the last interior knot.
- First-derivative continuity: Neighboring pieces have the same slope where they meet.
- Second-derivative continuity: Neighboring pieces have the same curvature where they meet.
How Cubic Spline Interpolation Works
Suppose the valid data points are sorted by x-value:
Each segment runs from \(x_i\) to \(x_{i+1}\). The spacing between adjacent x-values is
On segment \(i\), the spline uses a local coordinate
and a cubic polynomial of the form
The local coordinate matters. The coefficient \(a_i\), \(b_i\), \(c_i\), and \(d_i\) belong to one interval only. They are not the coefficients of one large polynomial for the entire data set.
A common way to build the spline is to solve for the second derivatives at the knots. Let \(M_i\) be the second derivative value at knot \(i\). For each interior knot, the second derivatives satisfy
for \(i=1,2,\ldots,n-2\).
These equations make the neighboring cubic pieces connect with matching slope and matching curvature. Two more equations are still needed at the endpoints. Those are supplied by the selected boundary condition.
For a natural spline, the endpoint curvature is set to zero:
For a clamped spline, the user supplies the endpoint slopes. If the left endpoint slope is \(s_L\) and the right endpoint slope is \(s_R\), the boundary equations are
and
For a not-a-knot spline, the first two segments are constrained to share the same third-derivative behavior at the first interior knot, and the last two segments are constrained similarly at the last interior knot. In the second-derivative form used here, this gives endpoint equations such as
and
This boundary condition needs at least four points because it refers to the first two and last two spline pieces.
After the second derivatives are found, each segment’s coefficients are calculated as
These coefficients let you evaluate the spline anywhere inside the segment by substituting \(t=x-x_i\) into the local cubic equation.
Examples of Cubic Spline Interpolation in Practice
Example 1: Natural spline through three points
Suppose the points are
A natural cubic spline has two segments because three points create two intervals. The natural endpoint condition sets the second derivative to zero at \(x=0\) and \(x=2\).
The resulting segment equations are
where \(t=x\), and
where \(t=x-1\).
At \(x=0.5\), the first segment uses \(t=0.5\):
The curve passes through all three points, has a smooth slope at \(x=1\), and uses zero curvature at the two endpoints.
Example 2: Clamped spline with specified endpoint slopes
Using the same points,
now suppose the curve should be flat at both ends. That means the endpoint slopes are
The clamped spline becomes
for the first segment and
for the second segment. The curve still passes through the same three points, but its endpoint behavior is different. The boundary condition changed the shape even though the data points did not change.
Example 3: Comparing a spline with one global polynomial
Imagine a data set with many points from an uneven curve. A cubic spline fits a local cubic on each interval, so changing one point mainly affects nearby segments. A Lagrange interpolating polynomial, by contrast, is one polynomial through all points.
The global polynomial can be useful as a comparison, but it is not the same as the spline. With many points, a global polynomial may swing more strongly between points or near the ends of the interval. The spline’s piecewise structure is often the better practical choice when the goal is a smooth interpolating curve with local behavior.
How to Interpret the Result
The most important result is the piecewise cubic spline itself. The graph shows the curve through the valid data points, and the segment table shows the equation used on each interval.
The segment count is the number of valid sorted points minus one. For example, five valid points create four cubic segments.
The boundary condition tells you which endpoint rule was used. Natural, clamped, and not-a-knot splines can all pass through the same points but produce different endpoint behavior.
The C1 continuity note means neighboring segments have matching first derivatives at interior knots. In practical terms, the curve has no sharp corner at those points.
The C2 continuity note means neighboring segments have matching second derivatives at interior knots. In practical terms, the curve’s curvature changes smoothly through the interior of the data range. For a natural spline, the endpoints also use zero second derivative.
The coefficient table should be read one row at a time. A row for \([x_i,x_{i+1}]\) gives the cubic equation for that interval only:
The units follow from the units of your data. If x is measured in seconds and y is measured in meters, then \(b_i\) is in meters per second, \(c_i\) is in meters per second squared, and \(d_i\) is in meters per second cubed. If your x and y values are unitless, the coefficients are unitless combinations of those coordinates.
The optional Lagrange comparison curve is not the spline result. It is a single interpolating polynomial through the same valid points and is best read as a visual comparison.
Common Mistakes and Misconceptions
A common mistake is entering repeated x-values. A spline treats y as a function of x, so one x-value cannot map to two different y-values. Nearly repeated x-values can also create numerical problems because the spacing \(h_i\) becomes extremely small.
Another mistake is expecting a cubic spline from only two points. Two points define one straight line segment, but they do not provide enough information for the spline system used here. At least three complete numeric points are required.
Not-a-knot splines need at least four points in this calculator. With only three valid points, choose a different boundary condition.
For clamped splines, the left and right derivative inputs are slopes, not endpoint y-values. Their units are y-units per x-unit. For example, if y is distance and x is time, a clamped derivative is a velocity-like value.
Do not mix units. If x-values are in seconds, both endpoint derivatives should use y-units per second. If some x-values are in minutes and others are in seconds, the coefficients and graph will not have a consistent meaning.
Do not treat the coefficient table as one global equation. The coefficients are local to their interval because each row uses \(t=x-x_i\).
When pasting data, remember that extra columns are ignored after the first two numeric values. A single numeric column is treated as y-values with x set to the row index. A first row is treated as a header only when all of its entries are nonnumeric; a mixed row such as 0, bad is rejected so that supplied data is not silently lost.
When to Use Cubic Spline Interpolation
Use cubic spline interpolation when you have known data points and want smooth estimates between them. It is especially useful when:
- the curve should pass through each supplied point;
- straight-line interpolation is too angular;
- a single global polynomial is too sensitive or oscillatory;
- the x-values are ordered measurements, samples, or knots;
- you want interval-by-interval cubic equations;
- endpoint slope or endpoint curvature assumptions matter.
Cubic splines are not the right tool when the data is noisy and you want a trend line, or when you need a statistical model with uncertainty estimates.
Limitations and Things to Keep in Mind
A spline is only as meaningful as the data and assumptions behind it. It passes through the input points, so inaccurate points can create inaccurate curve behavior.
The x-values must be distinct. Very close x-values can make the equations numerically sensitive because the spacing terms \(h_i\) appear in denominators and in the linear system.
All inputs must be finite, but finite values can still produce intermediate values or coefficients outside the calculator's numeric range. In that case the calculator stops with a range message instead of showing a graph or coefficients containing non-finite values. Rescale the coordinate values and try again.
Boundary conditions affect the shape near the ends. Natural splines are simple and often reasonable when no endpoint slope is known, but zero endpoint curvature is still an assumption. Clamped splines are helpful when endpoint slopes are known, but poor slope choices can distort the curve. Not-a-knot splines avoid specifying slopes or zero curvature, but they require enough points and can still be sensitive to the endpoint data.
The calculation is an interpolation over the span of the provided x-values. Values outside that range are extrapolations and may be unreliable because the spline is no longer anchored by data on both sides.
Displayed numbers are rounded. Very small displayed values may be shown as zero, ordinary numeric output may be shown with up to six decimal places, and very large or very small values may use exponential notation. Use the displayed coefficients as practical numeric results, not as exact symbolic expressions.
The calculator does not assign physical units automatically. You are responsible for keeping x-values, y-values, and clamped derivative values consistent.
For engineering, scientific, financial, safety-related, or official work, verify the inputs, review the boundary assumptions, and check important results with an appropriate method or qualified professional.
How to Use This Calculator
- Enter at least three complete x-y coordinate pairs, choose an example data set, or paste data into the import box.
- Add or delete rows as needed. Keep at least three rows available, and make sure the valid x-values are distinct.
- Choose a boundary condition: Natural, Clamped, or Not-a-knot.
- If you choose Clamped, enter numeric left and right endpoint derivatives in y-units per x-unit.
- Leave the Lagrange comparison enabled to compare the spline with a single global interpolating polynomial, or turn it off to focus only on the spline.
- Review the graph, segment count, continuity notes, and coefficient table.
- Use the graph hover to inspect spline values within the data range. You can also drag graph points to update the data interactively and download the graph as a PNG.
Frequently Asked Questions
How many points are needed for a cubic spline?
This calculator needs at least three complete numeric x-y points. Three points create two cubic segments. The not-a-knot boundary option needs at least four valid points.
Which boundary condition should I choose?
Choose Natural when you do not know endpoint slopes and a simple zero-curvature endpoint assumption is acceptable. Choose Clamped when you know the left and right endpoint slopes. Choose Not-a-knot when you want a common general-purpose spline condition that does not require slope inputs, provided you have at least four points.
What is the difference between natural and clamped splines?
A natural spline sets the second derivative at both endpoints to zero. A clamped spline sets the first derivative at both endpoints to user-supplied values. Both pass through the same data points, but they can curve differently near the ends.
Why are duplicate x-values not allowed?
The spline represents y as a function of x. If the same x-value has two different y-values, the function would be ambiguous. Duplicate or nearly duplicate x-values can also make the interval spacing too small for a stable spline system.
Are the coefficients one big cubic polynomial?
No. Each coefficient row belongs to one interval only. The formula uses the local variable \(t=x-x_i\), so the coefficients for one segment should not be used on another segment.
Is the Lagrange comparison curve the same as the spline?
No. The Lagrange comparison is one global interpolating polynomial through the valid points. The cubic spline is a collection of local cubic pieces joined smoothly at the knots.
Can I use the spline outside the input x-range?
Spline values are most meaningful within the x-range covered by the data. Outside that range, the curve is extrapolating from endpoint behavior and may not be reliable.
Sources and References
Books
- Carl de Boor. A Practical Guide to Splines. Revised edition, Springer, 2001. Relevant chapters on polynomial approximation, piecewise cubic interpolation, and spline interpolation. ISBN 978-0387953663. Google Books record.
- William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery. Numerical Recipes in Fortran 77: The Art of Scientific Computing. 2nd edition, Cambridge University Press, 1992. Section 3.3, “Cubic Spline Interpolation.” Section PDF.
Online and Educational Sources
- J. R. Buchanan. “Cubic Spline Interpolation.” MATH 375, Numerical Analysis, Millersville University, 2022. PDF.
- SciPy community. “scipy.interpolate.CubicSpline.” SciPy API Reference, accessed June 28, 2026. Documentation.
- Jean-Paul Berrut and Lloyd N. Trefethen. “Barycentric Lagrange Interpolation.” SIAM Review, 46(3), 501–517, 2004. DOI: 10.1137/S0036144502417715. SIAM page.