TL;DR
You have one dataset, and you want to know how much a number computed from it could vary. The bootstrap answers this by treating the dataset as a stand-in for the wider population: you draw new samples of the same size from it, with replacement, recompute the number each time, and look at how much those recomputed values spread out.
The method needs no formula for the uncertainty and works for almost any statistic, including medians, correlations and model coefficients that have no tidy textbook error formula.
Where you'll see it: in error bars on A/B test results, in the confidence intervals that statistics libraries report for medians and regression coefficients, and in bagging, where each tree in a random forest is trained on its own bootstrap sample.
Intuition
Sampling from the sample
Suppose you measure the response time of a server on five requests and get 12, 15, 9, 30 and 14 milliseconds. The average is 16 ms. How much would that average change if you had measured five different requests? Ideally you would just repeat the experiment many times and watch the spread. Usually you cannot.
The bootstrap's move is to pretend your five measurements are a good picture of all possible requests. If that is roughly true, then drawing from your five numbers is a cheap way to simulate new experiments. You draw five values from the list, one at a time, and after each draw you put the value back. That "put it back" is the replacement. Some values come up twice, some not at all, and the resulting list is a plausible-looking dataset of the same size. Compute its average, repeat a thousand times, and the thousand averages show you the likely range of the true average.
The idea that a sample can stand in for the population is the same reasoning that powers the Monte Carlo method. The difference is where the samples come from. Monte Carlo draws from a model you wrote down. The bootstrap draws from the data you already have.
Why replacement matters
Without replacement, every resample would be a shuffle of the original list, and every resample would have exactly the same mean. No spread, no uncertainty. Replacement lets each resample differ, and the differences between resamples are what we measure.
- share of distinct originals in one resample
- limit as n grows
Each resample of size leaves out a given original value with probability , which approaches for large . So a typical resample contains about 63% of the distinct originals, and the rest are duplicates. That is the source of variation.
The shape of the procedure
flowchart LR A["Original sample of n values"] --> B["Draw n values with replacement"] B --> C["Compute the statistic (mean, median, ...)"] C --> D["Repeat B times, often 1000 or more"] D --> E["Use the spread of the B values as uncertainty"]
The math
Setup
Let be the observed sample and let be the statistic we care about, such as the mean. The true value we would like to know is , the same statistic computed on the whole population. We want the sampling distribution of , meaning how it would vary across repeated samples of size .
The bootstrap sample
A bootstrap sample is drawn from the observed values, each draw independently and with equal probability . Write the bootstrap replicate of the statistic as for replicate .
The empirical distribution function puts probability on each observed value. Drawing from it is exactly what a bootstrap sample does, so the bootstrap replaces the unknown population distribution with . The cumulative distribution function (CDF) of is known to you; the one of is not.
Estimating the standard error
After replicates, the bootstrap standard error is the sample standard deviation of the replicates:
As grows, this estimate settles down. The remaining error comes from using finitely many resamples, and it shrinks like . The bigger source of error is whether is a good stand-in for , which depends on and on the data.
Percentile confidence intervals
Sort the replicates. A 95% percentile interval runs from the 2.5th to the 97.5th percentile of the replicates:
This needs no assumption that the statistic is Gaussian, which is its main appeal. It is also fragile for small , which we return to in the tradeoffs section.
Why it works for the mean
For the sample mean, the bootstrap standard error is close to the textbook answer , where is the sample standard deviation. You can see why from the variance rules. Each bootstrap draw has mean and variance , so the mean of draws has variance . This is the same formula that the variance of a sample mean gives, with the population variance replaced by its plug-in estimate. The bootstrap is worth using precisely when no such closed form exists.
Worked examples
Take three measurements: . The sample mean is . Draw five resamples of size 3, with replacement, and write down the mean of each.
- Resample 1: , mean .
- Resample 2: , mean .
- Resample 3: , mean .
- Resample 4: , mean .
- Resample 5: , mean .
The average of the five replicate means is . Their deviations from are , , , and . The squared deviations sum to , and dividing by gives . The square root is .
Interpretation: the mean of these three numbers is about 5, and the typical error is about 2. Five resamples is far too few for a real analysis. The point is that the procedure ran on nothing but the three numbers you started with.
You measured 11 latencies in milliseconds: 9, 11, 12, 12, 13, 14, 15, 15, 18, 22, 30. The median is 14 ms. You want a 95% interval for the true median.
- Draw resamples of size 11 with replacement and compute the median of each.
- Sort the 1000 medians. The 2.5th percentile is the 25th value, and the 97.5th percentile is the 975th value, counting from the bottom.
- Suppose the 25th value is 12 and the 975th is 18. The interval is ms.
- Interpretation: under the bootstrap approximation, values of the true median between 12 and 18 ms are consistent with these data. An interval like this need not be symmetric around 14: resampled medians can only take values from the data, and the data have a long right tail.
A caution that matters here: with only 11 points, the percentile interval is rough. Treat the endpoints as approximate, not exact to the millisecond.
Tradeoffs and failure modes
The bootstrap is a good default when you have a single dataset and an unusual statistic. It goes wrong in predictable ways.
| Situation | Problem | Better choice |
|---|---|---|
| Very small (under about 10 to 20) | The sample is too thin to stand in for the population; intervals are too narrow | Exact methods if the model is known; a parametric model with honest assumptions |
| Heavy tails, such as income or latency | Extreme values dominate; resamples may miss or repeat them unpredictably | Report a robust statistic, or use a larger sample |
| Dependent data, such as time series | Resampling single points destroys the ordering and correlation | Block bootstrap, which resamples contiguous chunks |
| Statistic is not smooth, such as the max | The bootstrap distribution can be badly wrong | Extreme value theory, or a different target |
| Data where observations are not independent of one another (clustered users, repeated measures) | Resampling rows treats correlated rows as independent, so intervals are too narrow | Resample at the cluster level |
| Needing a single exact answer for a textbook statistic | Simulation noise adds run-to-run variation | Use the closed form, and use the bootstrap only to check it |
The most common mistake is trusting a percentile interval from a few dozen points without a second look. The second most common is reporting a bootstrap interval from and forgetting that the endpoints move every time you rerun the code. Fix the random seed and use enough resamples.
History
Resampling ideas predate the bootstrap. The "jackknife", which recomputes a statistic with one observation left out at a time, was developed in the 1940s and 1950s by Quenouille and Tukey. The bootstrap itself was named and analysed by Bradley Efron in a 1979 paper in the Annals of Statistics, which showed that resampling could estimate standard errors and sampling distributions for statistics where theory was hard or absent.
It caught on for two reasons. Computers had become fast enough to run thousands of resamples in reasonable time, and the method asked nothing of the analyst except the ability to compute the statistic. Efron and Robert Tibshirani's 1993 book made the approach accessible to applied researchers, and it is now standard in statistical software. Leo Breiman's 1996 bagging method used bootstrap samples to train many models and average them, which connected the idea to machine learning.
Check yourself
QuestionWhat does drawing with replacement change compared with shuffling the original list?Show answer
Shuffling gives a permutation of the same values, so every resample has the same mean and there is no spread to measure. Sampling with replacement lets values repeat and go missing, so the resampled statistics vary, and that variation is the quantity the bootstrap uses to estimate uncertainty.
QuestionA dataset has values. What is the probability that one specific value is left out of a single bootstrap resample?Show answer
Each draw misses that value with probability , and the four draws are independent, so the probability is .
QuestionWhy is the bootstrap useful for the median, when a textbook formula for the median's standard error is awkward?Show answer
The procedure only needs the statistic to be computable on any dataset. You compute the median on each resample, and the spread of those medians estimates the standard error. No derivation of the median's sampling distribution is needed, and the same code works for any statistic.
QuestionYou run the bootstrap on 5 data points and report a 95% interval. What is the main concern?Show answer
Five points are too few for the empirical distribution to resemble the population well. The resamples can only contain those five values, so the interval will likely be too narrow. The estimate is only as good as the sample it resamples from, so the honest move is to report the interval with that caveat or to collect more data.
QuestionA web analytics table contains many page views per user. You bootstrap individual rows to get a confidence interval for average session length. Why might the interval be too narrow?Show answer
Page views from the same user are correlated. Resampling individual rows treats them as independent, which overstates the effective sample size. The fix is to resample users (the clusters) and carry all of each user's rows along with them.