Definition
The rule of three says that if independent trials, each with the same unknown failure probability , produce no failures, then is an approximate 95% upper confidence bound on . Such a bound is a number computed by a rule that, over many repetitions of the experiment, lies at or above the true at least 95% of the time. The exact bound for zero failures is , which slightly exceeds. Zero observed failures never show that is zero.
The idea
A test runs an operation 30 times and sees no failure. It is tempting to conclude that the operation does not fail. A process that fails on 10% of runs, however, passes all 30 with probability , about once in 24 such test series. If the failure probability were 10%, this clean outcome would occur in about 4.2% of experiments. That lower-tail probability puts 10% outside the exact one-sided 95% confidence interval §11.18 for this sample. The procedure can exclude the true probability in an unusually clean sample.
The value comes from asking which failure probabilities would make the clean record too surprising, meaning less likely than 5%. A failure probability of or more gives clean runs less than a 5% chance, so the clean record counts against it; the exact dividing line lies just below . The number 3 appears because , just under 0.05, where is the base of natural logarithms. The bound shrinks in proportion to : showing a failure probability below 1 in 1,000 at this confidence takes about 3,000 failure-free runs.
The 95% describes the rule, not one result: over many test series, at least 95% of the bounds the rule produces lie at or above the true failure probability. In this reading, called frequentist, the failure probability is fixed and only the bound varies, so 95% is not the probability that the true value lies below one computed bound.
How it works
The calculation rests on the binomial model.
Model. Each of trials fails with the same probability , independently of the other trials. Such trials are called Bernoulli trials, and their number of failures follows the binomial distribution.
Probability of a clean record. Each trial passes with probability , so all pass with probability , which falls as rises.
Exact bound. Every that gives a clean record a probability below 0.05 is rejected. The one-sided 95% upper bound is the boundary value, at which the clean record has probability exactly 0.05: . Taking the positive -th root gives , so . This is the zero-failure case of the Clopper–Pearson interval, the standard exact interval for a binomial probability.
Approximation. Taking natural logarithms, written , gives . For small , , so , which the rule of three rounds to .
A report may instead give a two-sided 95% interval, which leaves 2.5% of probability beyond each end. With zero failures its lower end is 0, and its exact upper end solves , which gives , because . Compare bounds only at the same confidence level and with the same number of sides.
The Wilson score interval, published by Edwin B. Wilson in 1927, is an approximate interval for a binomial probability [409]. Let be the number of failures in trials. Let be the distance from the center of the normal (bell-shaped) distribution, counted in standard deviations §11.14, beyond which the chosen tail probability lies: for a two-sided 95% interval and for a one-sided 95% bound. The interval contains every for which the observed fraction lies within standard deviations of , the standard deviation of the fraction being . With the condition squares to . Dividing by and solving for gives the upper end
Worked example
Take trials with no failure.
Exact one-sided 95% bound: , so , about 9.50%.
Rule of three: , which is 10%, slightly above the exact bound.
Exact two-sided 95% upper end: , so , about 11.57%.
Wilson two-sided 95% upper end: , so , about 11.35%.
Wilson one-sided 95% bound: , so , about 8.27%.
For the same calculations give 0.99% for the exact one-sided bound, 1.00% for the rule of three, 1.22% for the exact two-sided upper end and 1.26% for the Wilson two-sided upper end. The two-sided limits are larger because the equal-tailed procedure allocates only 2.5% to each tail. At zero failures, the upper endpoint solves the lower-tail equation for observing zero. For large the Wilson two-sided upper end is close to , about 28% above the rule of three. Report the observed count and the procedure together. Zero failures in 30 independent trials give a one-sided exact 95% upper confidence limit of 9.50%; zero in 300 give 0.99%. The confidence level describes coverage under repeated sampling.
Stated precisely
Let be the number of failures in trials, and let , with , be the accepted error probability: for 95% confidence. When the exact bound is ; when the Clopper–Pearson rule gives a larger bound. The guarantee: for every true failure probability , the probability, over repetitions of the whole test, that the reported bound lies below is at most . It depends on four assumptions.
Independence: the outcome of one trial does not change the failure probability of another.
One common probability: every trial has the same failure probability .
A fixed plan: and the rule for stopping were fixed before any result was seen.
Relevant trials: the trials come from the conditions the claim is about.
Because and for every , the exact bound satisfies . For this gives for every . The rule of three therefore always slightly overstates the exact one-sided 95% bound, erring on the safe side, and the ratio of the exact bound to approaches as grows.
The Wilson interval has no such guarantee. Its coverage, the long-run fraction of computed intervals that contain the true , is close to the stated level on average but falls below it for some . At its one-sided zero-failure bound is 8.27%, below the exact 9.50%. For a true between the two, a clean record has probability above 0.05 and then gives a Wilson bound below , so the bound misses more than 5% of the time.
If the trials are independent but trial has its own failure probability , fixed in advance, a clean record has probability , the product of the pass probabilities. That product is at most , where is the average of the , by the inequality between the geometric and the arithmetic mean §11.12. The zero-failure bound therefore remains valid for , the average failure probability over the mix of trials actually run, and for nothing narrower.
Limits and common mistakes
Fuzzing §10.9, which runs a program on very many automatically generated inputs to find crashes, does not fit the model. A coverage-guided fuzzer makes each new input by changing an earlier one, steered by which code the earlier inputs reached, so its inputs are not independent, their distribution changes during the campaign, and it is not the distribution the program meets in use. A million crash-free executions therefore do not show a failure probability below for any population that matters.
Pooled rows of different fault types bound only the average over the mix that was tested. A fault type that made up 5 of 300 clean rows has its own exact bound of , that is 45%. When the claim is about each fault type, bound each type from its own rows.
The count must follow a plan fixed in advance. A plan such as ‘keep testing until 30 runs in a row pass’ always ends with 30 clean runs if the failure probability is below 1, so that record carries no evidence through this formula. Runs made before a fix come from a different program and cannot be pooled with runs made after it.
A deterministic check, one whose outcome depends only on its input, has no failure probability to bound when one input is repeated: 200 runs of the same input are one observation made 200 times. With randomly drawn inputs, the bound covers only the fraction of that random distribution that the check mishandles. The claim that the check rejects every malformed input concerns all inputs, and an attacker chooses inputs instead of drawing them at random. That claim needs an argument about the code, such as a proof, a static analysis §3.1 or exhaustive testing §10.33 of a finite input space.
With the formula is undefined: no trials give no bound. A bound on the probability per trial is also not the probability that a long deployment never fails. With , the chance of at least one failure in 1,000 uses is , about 63%.
Questions answered
Can this be applied to fuzz executions or heterogeneous fault rows?
Not directly. The rule of three, which turns zero failures in trials into an approximate 95% upper bound of on the failure probability, assumes independent trials that share one failure probability, a number of trials fixed in advance, and trials drawn from the conditions the claim is about. Fuzz executions break these assumptions: a fuzzer, a tool that runs a program on very many automatically generated inputs, builds each input from earlier ones and changes its input distribution as it goes, and that distribution is not the one the program meets in use. A count of crash-free fuzz executions supports no failure-probability bound; it shows only that the fuzzer found no crash.
Heterogeneous fault rows, independent trials of different fault types with different failure probabilities, support a bound only on the average failure probability over the mix that was tested, and only if that mix was fixed in advance. That average says nothing about any one fault type. For a claim about each type, apply the bound to each type’s own rows: 5 clean rows of one type give an exact one-sided 95% bound of . For a deterministic check, whose outcome depends only on its input, no failure-rate bound shows that the check handles every input; that needs an argument about the code.
Related entries: Confidence interval (§11.18), Independent and identically distributed samples (§11.5), Fuzzing (§10.9), Fault model (§1.30), Why fuzzing cannot certify universal safety (§17.18). Further reading: [185, 409].