The guide
Bisection: why halving a bracket works, and what it can quietly get wrong
Half the bracket is thrown away at every step, so the count follows from the tolerance. The sign test behind it can still be fooled by a pole, and a small residual proves nothing.
- 20 steps for a tolerance of 1e-6 on a bracket of width 1
- 1.5213797 the root of x^3 - x - 2, from a 50 digit check
- 741455/524288 left end of the exact bracket for the square root of 2
- 6.06e+12 size of tan x at the end of a run that found a pole
- 0.125 where a residual stop wrongly ends for x^9, root 0
Read the full guide Fold the guide
Lay a beam across a ridge and ask where it balances. You push one post in from each end, always keeping the balance point between them. Each push halves the space left to search. That is the whole method, and it is slower than most others and almost impossible to break. The trouble starts when people trust it for the wrong reasons.
Why a sign change guarantees a root
The Wikipedia article on the bisection method sets the stage. You need a continuous function f and two numbers a and b where f(a) and f(b) have opposite signs. The intermediate value theorem then says the function must cross zero somewhere between them.
Think of drawing the curve without lifting the pencil. If it starts below the axis and ends above it, the line has to cross. Nothing else is needed, and nothing less will do. Take f(x) = x^3 - x - 2. At x = 1 it equals -2 and at x = 2 it equals 4, the same pair the Wikipedia article uses. The signs differ, the cubic is continuous, so a root lies in [1, 2]. The method does not tell you where. It only promises the root is not outside.
Each step takes the midpoint c = (a + b) / 2 and looks at the sign of f(c). If f(c) has the sign of f(a), the root is in the right half and a moves up to c. Otherwise b moves down. The Wikipedia article adds a useful detail: once the process starts, the signs at the two ends never change.
Why the bracket halves and the count follows
Every step removes half the bracket, so after k steps its width is the starting width divided by 2^k. The midpoint of a bracket sits at most half a width from any root inside it. That gives the error bound after step k as (b - a) / 2^k, a figure you can state before running anything.
Turn it around and you can count steps from a tolerance. You want the smallest k for which (b - a) / 2^k is below the tolerance. In words, take the base-2 logarithm of width over tolerance and round up. Python’s math module lists exactly those two operations, log2 and ceil.
For the cubic, the width is 1. A tolerance of 1e-6 needs 20 steps, because 2^-20 is about 9.5e-7 and 2^-19 is about 1.9e-6. A tolerance of 1e-12 needs 40. The count does not depend on the function at all, only on the width and the tolerance.
Rounding down is a classic slip. A tolerance of 1e-3 on a width of 1 gives a logarithm of about 9.97. Rounding down says 9 steps, but 2^-9 is 0.00195, which is above 0.001. Ten steps are needed, and the ceiling gets that right. A tolerance that is exactly a power of two needs one step more than the ceiling gives, because the width must be strictly below it.
Now follow the first few steps. The midpoints are 1.5, 1.75, 1.625 and 1.5625, and f(1.5) is -0.125, so the root is above 1.5. The ninth midpoint is 1.5214844 with f = 0.0006222. After 20 steps the estimate is 1.5213804, within the bound of 9.5e-7 of the root. An independent 50-digit calculation puts that root at 1.5213797068.
The method is slow by design. The mpmath documentation calls it robust and reliable, notes that it converges slowly, and says it needs a sign change. The SciPy documentation says much the same of its bisection routine: slow but sure. Its brentq combines bracketing, bisection and inverse quadratic interpolation, and the documentation calls it generally the best of the root-finding routines it lists.
Why the width is the thing to watch, not the residual
A tempting rule is to stop when |f(c)| is small. The Wikipedia article lists it among the stopping conditions and then warns that it does not give a result accurate to within the tolerance unless the slope near the answer has size at least 1. A tiny residual says the curve is near the axis, not that c is near the root.
Try f(x) = x^9 on [-1, 2]. The true root is 0. The first midpoint is 0.5, with f = 0.00195. The second is -0.25, with f about -3.8e-6. The third is 0.125, and f(0.125) is about 7.5e-9, already below 1e-6. A residual rule stops there and reports 0.125.
That answer is off by 0.125, while the honest bound after three steps is 0.375. The function is so flat near zero that a large error hides inside a small residual. Stopping on the width instead takes 22 steps for the same tolerance, and ends within 7.2e-7 of zero.
The residual also misleads the other way. A function with a steep slope can have a large |f(c)| while c is already extremely close to the root. Neither size of residual is a reliable judge of how far away the root is. The bracket width is: it is exactly what you know, and it shrinks on a schedule.
There is a floor to all this. The MDN page for Number.EPSILON gives the gap between 1 and the next larger double as 2^-52, about 2.22e-16. Once the bracket is only a few such gaps wide, the midpoint cannot be told apart from an end. A tolerance below that is out of reach, and a good tool says so instead of looping.
How a pole fools the sign test
The sign test asks only whether f(a) and f(b) differ in sign. It does not check that f is continuous between them. A pole breaks continuity and still flips the sign.
The DLMF defines the tangent as sine over cosine, and gives the zeros of cosine at (k + 1/2) times pi. So tan x is not defined at pi/2, which is about 1.5707963, and it swings from huge positive values to huge negative ones across it.
Run bisection on tan x over [1, 2]. The ends are tan 1 = 1.557 and tan 2 = -2.185, opposite in sign, so the test passes. Forty halvings, for a tolerance of 1e-12, close in on 1.570796327. The function there has size 6.06e+12, thousands of billions. That is not a root. It is the pole, found by a method that only watched signs.
A cheap defense is to compare |f(c)| at the end with |f| at the original ends. A real root drives the function toward zero, so the final value should be smaller than both. A value larger than both, as with the tangent, is a strong hint of a pole or a jump. It is a hint and not a proof, which is why a page should call it a warning.
Scanning helps in the opposite direction. Split a range into equal pieces and list every piece whose ends differ in sign. For sin x over [1, 10] in 90 pieces, three pieces change sign, and bisecting each gives 3.141592654, 6.283185307 and 9.42477796, which agree with pi, 2 pi and 3 pi to about nine digits. A scan of tan x lists the pole alongside the true zeros, so each hit still needs the check above.
Exact fractions, and what the method cannot do
Floating-point numbers are binary fractions. The Python tutorial shows that 1/10 is stored as 3602879701896397 / 2 ** 55, close to one tenth but not equal. For a polynomial with rational coefficients, you can avoid that by working in exact fractions. The Python fractions module supports rational arithmetic for this purpose, and in a browser, BigInt values hold whole numbers beyond what a double can.
Run x^2 - 2 on [1, 2] for 20 steps in exact arithmetic. The bracket is 741455/524288 to 1482911/1048576. Its width is exactly 1/1048576, which is (b - a) / 2^20, with no rounding anywhere. Each end is a fraction you can check by hand, and the root, the square root of 2, lies between them. Heavy sweeps do not belong on the thread that draws the page. The MDN overview of web workers describes running a script in a background thread, separate from the main one, so the page stays responsive while a long scan or an exact run finishes.
Know what bisection cannot do. It needs a sign change, so it cannot find a root where the curve touches zero without crossing, such as (x - 1)^2 at x = 1. It finds one root per bracket, so two roots in one bracket cancel out and the test refuses the bracket. It does not handle complex roots or systems of equations. And it trusts continuity, which only you can check.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Bisection method - Wikipedia Wikipedia (CC BY-SA 4.0)
- bisect - SciPy v1.18.0 Manual The SciPy community
- brentq - SciPy v1.18.0 Manual The SciPy community
- Root-finding and optimization - mpmath 1.3.0 documentation Fredrik Johansson and mpmath developers
- DLMF: 4.14 Definitions and Periodicity (Trigonometric Functions) NIST Digital Library of Mathematical Functions (US government)
- Number.EPSILON - JavaScript | MDN MDN Web Docs (Creative Commons licence)
- BigInt - JavaScript | MDN MDN Web Docs (Creative Commons licence)
- Web Workers API - Web APIs | MDN MDN Web Docs (Creative Commons licence)
- fractions - Rational numbers - Python documentation Python Software Foundation
- Floating-Point Arithmetic: Issues and Limitations - Python documentation Python Software Foundation
- math - Mathematical functions - Python documentation Python Software Foundation