Buffon's Needle, Explained
After reading this you will know why dropping needles on a lined floor estimates π, how to turn a count of crossings into a number near 3.14159, and why the estimate crawls toward the truth instead of racing.
What it is, with one throw to fix the idea
Picture a floor of parallel lines, all spaced the same distance apart. Call that spacing t. Now drop a needle of length L onto the floor, with L \le t so the needle can never cross two lines at once. Sometimes the needle lands clean between two lines. Sometimes it lands across a line. Georges-Louis Leclerc, Comte de Buffon, asked in 1733 how often it crosses. The answer he found in 1777 contains π.
The crossing probability is \frac{2L}{\pi t}. Take a needle exactly as long as the spacing, so L = t. Then the probability is \frac{2}{\pi} \approx 0.6366. Drop 1000 such needles and about 637 should cross a line. Turn that around: if you counted 637 crossings out of 1000 throws, you would estimate \pi \approx \frac{2 \cdot 1000}{637} \approx 3.140. You measured π with a box of needles and no circle in sight.
The circle is hidden in the geometry of a rotating line. π enters through the angle the needle makes with the floor lines, and that is the whole trick.
When this is the right lens, and when it is not
Use Buffon's needle to see how randomness can compute a constant, and to feel the pace of Monte Carlo convergence in your bones. It is a clean example because the exact answer is known, so you can watch the error and check it against theory.
Do not use it to actually compute π. It is one of the worst π estimators ever devised. To pin down π to three correct decimals you may need millions of throws, and even then a single unlucky run can miss. Faster methods exist: a few terms of a good series beat billions of needles. Treat this as a teaching model, not a calculator.
The needle experiment is a physical Monte Carlo integration. You are estimating an integral over the needle's position and angle by sampling it at random. The same idea drives the more general Monte Carlo Playground, which throws darts at shapes to estimate areas and integrals.
The formula and where π comes from
Fix the needle after it lands. Two things describe how it sits: the distance x from the needle's center to the nearest line, and the acute angle \theta between the needle and the lines. By symmetry, x is uniform on [0, t/2] and \theta is uniform on [0, \pi/2].
The needle crosses the nearest line exactly when its half-length projected perpendicular to the lines reaches across the gap:
Here \frac{L}{2}\sin\theta is how far each half of the needle sticks out toward a line for a given tilt. A needle lying flat along the lines (\theta = 0) reaches nothing and almost never crosses. A needle standing perpendicular (\theta = \pi/2) reaches its full half-length L/2 and crosses most often.
Average the crossing condition over all positions and angles. The probability is the favorable area divided by the total area of the (x, \theta) rectangle:
The integral \int_0^{\pi/2}\sin\theta\, d\theta = 1, and the rest is bookkeeping. That lone π in the denominator is the angle's range \pi/2 refusing to cancel. Solve for π to get the estimator:
Here N is the number of throws and C is the number that crossed. The estimate is only as good as the ratio C/N, which is a noisy measurement of the true probability.
A worked example reproducing the demo
The demo uses the defaults: needle length equal to line spacing, so L = t = 1. With those, the estimator simplifies to \hat{\pi} = 2N/C. Suppose you drop 10000 needles and 6362 of them cross a line.
From 10000 throws to an estimate of π
- Record the counts:
N = 10000throws,C = 6362crossings. - Compute the crossing rate: C/N = 6362/10000 = 0.6362. The true value is 2/\pi = 0.63662, so you are close.
- Apply the estimator: \hat{\pi} = 2N/C = 20000/6362 \approx 3.1437.
- Check the error: |3.1437 - 3.14159| \approx 0.0021, about 0.07 percent.
Now imagine one unlucky run of only 100 throws that gave 60 crossings. Then \hat{\pi} = 200/60 \approx 3.333, an error of 0.19. One extra crossing (61) would give 3.279, and one fewer (59) would give 3.390. At small N, every single crossing swings the answer by a lot. That sensitivity is why small samples are useless here.
Reading the running estimate
The headline behavior is slow convergence. The standard error of the estimated probability falls like 1/\sqrt{N}, and the π estimate inherits that rate. Concretely, the error shrinks roughly as \frac{\sqrt{\pi(\pi-2)}}{2\sqrt{N}} for the L=t case, about 0.65/\sqrt{N}. Plug in numbers and you get a table you can sanity-check against your own runs.
| Throws N | Typical error | Estimate usually within |
|---|---|---|
| 100 | 0.065 | 3.08 to 3.21 |
| 1000 | 0.021 | 3.121 to 3.163 |
| 10000 | 0.0065 | 3.135 to 3.148 |
| 100000 | 0.0021 | 3.1395 to 3.1437 |
| 1000000 | 0.00065 | 3.1409 to 3.1422 |
Notice each row multiplies N by 10 and cuts the error by about 3.16, which is \sqrt{10}. To gain one more correct decimal digit (a tenfold drop in error) you need 100 times more throws. This is the plain arithmetic of 1/\sqrt{N}.
Common mistakes
The errors here are small in code but large in effect.
The formula \hat{\pi} = 2LN/(tC) requires L \le t. If the needle is longer than the spacing, it can cross two lines at once, and a simple crossing count no longer matches 2L/(\pi t). The long-needle case needs a different formula (the general Buffon-Laplace result), so keep L \le t.
A second trap is division by zero: if C = 0, the estimate 2LN/(tC) blows up. With any reasonable N this never happens, but a run of 3 throws with no crossings gives nonsense. Third, watch what you sample. The angle \theta must be uniform on [0, \pi/2] and the offset x uniform on [0, t/2]. Sampling the needle's two endpoints uniformly instead biases the angle and quietly breaks the estimate.
Finally, do not read too much into one lucky run. If your first 500 throws give exactly 3.14159, that is coincidence, not accuracy. Run it again and the digits will move. Judge the method by the spread across many runs, not by one pretty number.
Related tools worth a look
If the randomness-computes-a-number idea grabs you, the Law of Large Numbers demo shows the same averaging settling onto an expected value, and the Central Limit Theorem Demo explains why the error is bell-shaped and why it shrinks like 1/\sqrt{N}. For a hands-on view of Monte Carlo estimation of areas, try the Monte Carlo Playground. To watch chance build a smooth distribution from nothing, drop balls through the Galton Board. And the Random Walk Explorer makes the same square-root scaling visible in the spread of a wandering path.
Frequently asked questions
Why does π appear at all when there is no circle?
π enters through the needle's angle. Averaging the crossing condition over all tilts involves integrating over the angle range [0, \pi/2], and that range carries a factor of π that does not cancel. Rotation is where circles hide inside straight-line geometry.
How many needles do I need for π to two decimals?
To get a typical error near 0.005 you need about 17000 throws, since 0.65/\sqrt{N} = 0.005 gives N \approx 16900. Even then a single run can be off in the second decimal. For reliable two-decimal accuracy across runs, plan on 100000 or more.
What happens if the needle is longer than the line spacing?
Then a needle can cross two lines at once, and counting throws that cross at least one line no longer equals 2L/(\pi t). You would count total crossings and use the expected number per throw, which for L \le t also equals 2L/(\pi t) but diverges from the simple probability once L \gt t. Keep L \le t to use the estimator on this page.
Why is the estimate so jumpy at small counts?
Because the estimate depends on the integer count C. With N = 100, moving from 63 to 64 crossings changes 2N/C from 3.175 to 3.125, a jump of 0.05 from one needle. Only at large N does a single crossing barely move the answer.
Is this actually how people measured π historically?
Not seriously. A few 19th-century experimenters reported needle-drop estimates of π, and at least one famous run of 3408 tosses gave 3.1415929, suspiciously good. Such a result almost certainly came from stopping at a lucky moment. The method is a fine illustration and a poor instrument.