On this page
In calculus you learn that f′(x) is the limit of (f(x + h) − f(x))/h as h → 0. A computer cannot take a limit, so it picks a small h and divides. The surprise is that making h smaller stops helping long before h reaches zero, and then starts to hurt.
What are the forward and central difference formulas?
The forward difference is (f(x + h) − f(x))/h. Taylor's theorem gives f(x + h) = f(x) + hf′(x) + ½h²f″(ξ), so the forward difference is off by ½h·f″(ξ): its truncation error is O(h), which is why it is called first-order accurate (Alexanderian, NC State University).
The central difference is (f(x + h) − f(x − h))/(2h). The first-order errors cancel, leaving an error of −f‴(c)h²/6, so the central difference is O(h²) (Numerical differentiation, Wikipedia). Halve h and the forward error halves, while the central error drops to a quarter.
Why does making h smaller make the derivative worse?
A computer stores each number with a relative error within about machine epsilon ε, which is about 2.2 × 10⁻¹⁶ in double precision (Alexanderian). Python defines this epsilon as the gap between 1.0 and the next larger number it can store (Python sys.float_info).
So f(x + h) and f(x) each carry a tiny error. Subtracting two nearly equal numbers cancels their shared leading digits but keeps the errors, and dividing by h magnifies what is left. K. Ming Leung's lecture notes bound the forward difference's rounding error by 2ε/h and its total error by Mh/2 + 2ε/h, where M bounds |f″| (Leung, Polytechnic University). As h shrinks, the first term falls and the second climbs. It is the same rounding as in why 0.1 + 0.2 ≠ 0.3 on a computer, multiplied by 1/h.
Take the extreme case h = 10⁻¹⁶. The next number above 1 that a double can store is 1 + 2.2 × 10⁻¹⁶, so 1 + 10⁻¹⁶ rounds back to exactly 1. The numerator becomes zero, the computed derivative of sin at x = 1 is 0, and the error is all of cos 1 ≈ 0.54.
What is the optimal step size for numerical differentiation?
In Leung's notes, setting the derivative of Mh/2 + 2ε/h to zero gives h = 2√(ε/M), with a minimum error of 2√(Mε). At that step, truncation and rounding contribute equally (Leung).
For the forward difference the optimal step is of order ε^(1/2), and for the second-order central difference it is of order ε^(1/3) (Alexanderian). In numbers, √ε ≈ 1.5 × 10⁻⁸ and ∛ε ≈ 6 × 10⁻⁶ (Kostyrka, pnd package vignette). In Alexanderian's test on 1/(x² + 1), the best steps were indeed around 10⁻⁸ for the forward difference and 10⁻⁶ for the central difference. The central formula can use a larger h because its truncation error falls faster, and a larger h means less rounding.
Wikipedia scales the forward step to x: h = √ε · x (Wikipedia).
Worked example: how big is the error for sin at x = 1?
Kostyrka's vignette uses this test as its first example (Kostyrka); the true answer is cos 1 ≈ 0.5403023. Below are the errors |estimate − cos 1| to two significant figures. We worked out the rows from h = 10⁻¹ to 10⁻⁴ from the Taylor error terms, about (h/2)·sin 1 for the forward difference and (h²/6)·cos 1 for the central difference. At these steps the rounding bound ε/h is below 10⁻¹¹, so it does not change the figures shown.
h = 10⁻¹: forward 4.3 × 10⁻², central 9.0 × 10⁻⁴
h = 10⁻²: forward 4.2 × 10⁻³, central 9.0 × 10⁻⁶
h = 10⁻³: forward 4.2 × 10⁻⁴, central 9.0 × 10⁻⁸
h = 10⁻⁴: forward 4.2 × 10⁻⁵, central 9.0 × 10⁻¹⁰
h ≈ 3 × 10⁻⁸: the forward difference is at its best. By our arithmetic from Leung's formulas with M = sin 1 ≈ 0.84, h = 2√(ε/M) ≈ 3 × 10⁻⁸ and the error bound 2√(Mε) ≈ 3 × 10⁻⁸
h ≈ 8 × 10⁻⁶: the central difference is at its best; Kostyrka gives the true optimum as ∛(1.5 ε tan 1) ≈ 8 × 10⁻⁶
h = 10⁻¹⁶: the forward difference returns 0, an error of 0.54
Each tenfold cut in h gains one correct digit for the forward difference and two for the central difference, until rounding takes over. Leung's notes plot this trade-off for the forward difference on log-log axes: a clean straight line where truncation dominates, then a noisy climb where rounding dominates, with the lowest errors near h = 10⁻⁸.
How do you choose h in practice?
Prefer the central difference. If you already have f(x), it costs one extra evaluation and gives far more accuracy.
Start from h = √ε·|x| for the forward difference or ∛ε·|x| for the central difference. A common safeguard is to use 1 in place of |x| when x is near zero.
Check by halving h. The forward error should roughly halve and the central error should drop to a quarter. If the answer jumps around instead, you are in the rounding zone, so increase h.
If f comes from a simulation, use that simulation's error in place of ε. In Alexanderian's tests, a solver with error of order 10⁻⁶ had its best step near 10⁻³, and one with error of order 10⁻⁹ had its best step near 10⁻⁵ (Alexanderian).
Need more digits? Combine two step sizes with Richardson extrapolation using h and h/2 instead of shrinking h.
If the limit definition behind all this still feels shaky, the derivative has its own lesson in the Fermi Concept Library. You can then test yourself on JEE Main limits and derivatives questions.
Next time a numerical derivative looks wrong, check the size of h before you check the formula.



