Natural & Clamped Cubic Spline Calculator

Enter five points to construct a piecewise cubic that passes through each one. Choose natural endpoints or supply endpoint slopes for a clamped spline, then inspect the polynomial used at your selected x-value.

Your numbers
Enter the first x-coordinate; x-values must increase strictly.
Enter the observed value at x₀.
Enter the second x-coordinate.
Enter the observed value at x₁.
Enter the third x-coordinate.
Enter the observed value at x₂.
Enter the fourth x-coordinate.
Enter the observed value at x₃.
Enter the fifth x-coordinate.
Enter the observed value at x₄.
Natural sets endpoint second derivatives to zero; clamped uses supplied endpoint slopes.
Enter S′(x₀); this input is used only for a clamped spline.
Enter S′(x₄); this input is used only for a clamped spline.
Choose the x-coordinate at which to calculate the spline and its derivatives.

What this calculator leaves out

  • This calculator fits exactly five data points and does not perform regression or smooth noisy observations.
  • Extrapolation uses the nearest cubic segment and can become unreliable rapidly outside the supplied x-range.
  • Natural endpoint conditions are mathematical assumptions, not evidence that the underlying function has zero endpoint curvature.

By using this calculator you agree to the Terms of Use. Results are estimates, not professional advice.

Interpolated value S(x)0.45

First derivative S′(x)
1.39
Second derivative S″(x)
0.43
Active interval
[2, 3]
Piecewise spline equations
S0(x) = 0 + 1.71428571 × (x − 0) + 0 × (x − 0)² − 0.71428571 × (x − 0)³; S1(x) = 1 − 0.42857143 × (x − 1) − 2.14285714 × (x − 1)² + 1.57142857 × (x − 1)³; S2(x) = 0 + 0 × (x − 2) + 2.57142857 × (x − 2)² − 1.57142857 × (x − 2)³; S3(x) = 1 + 0.42857143 × (x − 3) − 2.14285714 × (x − 3)² + 0.71428571 × (x − 3)³
Node second derivatives
M0 = 0; M1 = -4.28571429; M2 = 5.14285714; M3 = -4.28571429; M4 = 0
Continuity check
Largest value, slope, or curvature mismatch: 0
Spline coefficients by interval
Intervalaᵢbᵢcᵢdᵢ
S001.714285710-0.71428571
S11-0.42857143-2.142857141.57142857
S2002.57142857-1.57142857
S310.42857143-2.142857140.71428571

Uses natural endpoint conditions and unrounded coefficients for every calculation.

How to use this calculator

  1. Enter five points in strictly increasing x order; their spacing does not need to be equal.
  2. Choose Natural to set endpoint curvature to zero, or Clamped to specify the starting and ending slopes.
  3. Enter the x-value where you want the spline and its first two derivatives evaluated.
  4. Review the active interval, piecewise equations, coefficients, and continuity check before using the result.

How the cubic spline is calculated

A cubic spline uses one cubic polynomial between every neighboring pair of points. This calculator has five nodes, so it constructs four pieces. Each piece reaches its two endpoint values, and adjacent pieces share the same value, first derivative, and second derivative at their common knot. That last condition is why a cubic spline is described as twice continuously differentiable.

For each interval, let hᵢ = xᵢ₊₁ − xᵢ, Δᵢ = (yᵢ₊₁ − yᵢ) ÷ hᵢ, and Mᵢ = S″(xᵢ). At the three interior nodes, the calculator solves:

hᵢ₋₁Mᵢ₋₁ + 2(hᵢ₋₁ + hᵢ)Mᵢ + hᵢMᵢ₊₁ = 6(Δᵢ − Δᵢ₋₁)

A natural spline adds M₀ = M₄ = 0. A clamped spline instead uses your endpoint slopes s₀ and s₄: 2h₀M₀ + h₀M₁ = 6(Δ₀ − s₀) and h₃M₃ + 2h₃M₄ = 6(s₄ − Δ₃). These five equations determine the five node curvatures.

On interval [xᵢ, xᵢ₊₁], with t = x − xᵢ, the displayed polynomial is Sᵢ(x) = aᵢ + bᵢt + cᵢt² + dᵢt³. Its coefficients are aᵢ = yᵢ, bᵢ = Δᵢ − hᵢ(2Mᵢ + Mᵢ₊₁) ÷ 6, cᵢ = Mᵢ ÷ 2, and dᵢ = (Mᵢ₊₁ − Mᵢ) ÷ (6hᵢ). The tool differentiates that same unrounded polynomial to return S′(x) and S″(x).

Choosing the boundary condition

Natural endpoints are useful when zero curvature is a reasonable mathematical convention and no endpoint slope is known. Clamped endpoints are more appropriate when you know how the quantity is changing at both ends. The boundary condition can noticeably change the first and last intervals, and sometimes the interior as well. Uneven x-spacing is valid; only strictly positive interval widths are required.

What the result does not establish

The continuity check verifies the constructed pieces against one another in floating-point arithmetic. It does not show that the curve is an accurate model between measurements. This calculator fits exactly five observations, does not smooth noise or perform regression, and does not choose endpoint slopes for you. Outside the first and last x-values it reuses the nearest cubic piece, which can become unreliable quickly.

Worked example

Enter x = 0, 1, 2, 3, 4 and y = 0, 1, 0, 1, 0 with natural endpoints. The solved node curvatures are 0, −30/7, 36/7, −30/7, 0. On the interval from 2 to 3, the equation is S₂(x) = (18/7)(x − 2)² − (11/7)(x − 2)³.

At x = 2.5, that equation returns S(x) = 25/56, about 0.44642857. Its first derivative is 39/28, about 1.39285714, and its second derivative is 3/7, about 0.42857143. The coefficient table reports the same interval in the local x − xᵢ form.

Common questions

What is the difference between a natural and clamped cubic spline?

A natural cubic spline sets the second derivative to zero at both endpoints, which controls curvature but does not prescribe endpoint direction. A clamped cubic spline uses the first derivative, or slope, at both endpoints instead. Both pass through every entered point and keep the value, slope, and curvature continuous at interior knots.

How are cubic spline coefficients calculated?

The calculator first solves a tridiagonal system for the second derivative at every node. It then uses each interval width, secant slope, and neighboring pair of second derivatives to calculate a, b, c, and d in the local cubic. Keeping the polynomial local to its left endpoint avoids the less stable expanded-power form.

Do spline x-values have to be equally spaced?

No. Cubic spline interpolation works with uneven x-spacing as long as every x-value is strictly greater than the previous one. Repeated or decreasing x-values make an interval width zero or negative, so the required system cannot be formed.

How do I choose endpoint slopes for a clamped spline?

Use a measured rate of change, a derivative supplied by the underlying model, or a defensible physical constraint. Avoid choosing slopes solely to make the plot look smooth, because endpoint assumptions affect the full curve. If no slope information is available, natural conditions are a transparent default rather than evidence of zero curvature.

Can a cubic spline calculator extrapolate beyond the data?

Yes. This calculator uses the first cubic segment to the left of the data and the last segment to the right, and labels the result as extrapolation. A spline is constrained by observations inside the range, not outside it, so extrapolated values and derivatives can change quickly.

How does cubic spline interpolation differ from polynomial interpolation?

Ordinary polynomial interpolation uses one global polynomial, so changing one point can change the curve everywhere. A cubic spline uses a separate cubic on each interval and joins neighboring pieces smoothly. That local structure is often better behaved for data at several x-values, but it still depends on the endpoint condition.

Put this calculator on your site

Paste the snippet below where you want the calculator to appear. It stays up to date automatically and links back here.

<iframe src="https://countfolk.com/embed/cubic-spline-interpolation-calculator/" title="Natural & Clamped Cubic Spline Calculator" width="100%" height="640" style="border:0;max-width:44rem" loading="lazy"></iframe>