Written and maintained by CASRAI Editorial Board
Last updated
The binomial test is an exact test for one yes/no outcome: given n independent trials, does the observed number of successes differ from what a hypothesised success probability p0 predicts? Because it sums probabilities straight from the binomial distribution, it needs no normal approximation and stays valid for small samples. This guide gives the formula, a fully worked example in which the one-sided and two-sided answers disagree, and working snippets for Excel, R and Python.
What is the binomial test?
The binomial test (also called the exact binomial test) compares an observed count of successes k out of n trials with the count expected under a null hypothesis H0: the true success probability equals p0. The p-value is the probability, under H0, of a result at least as extreme as the one observed. R documents this as binom.test (“Exact binomial test”), and SciPy provides scipy.stats.binomtest. Use it for questions such as whether 10 of 20 sampled items are defective when the historical defect rate is 30%.
What is the binomial distribution?
The binomial distribution gives the probability of exactly x successes in n trials when each trial has two possible outcomes and the success probability p is fixed for every trial (NIST/SEMATECH Engineering Statistics Handbook). Its mean is np and its standard deviation is √(np(1 − p)). For the parameters in depth, see binomial distribution parameters and the comparison Bernoulli vs binomial distribution.
What is the binomial probability distribution?
It is the same object: the probability mass function P(x; p, n) listing the probability of every possible success count from 0 to n. The test is built by adding up entries from this list.
Formula and every symbol
Probability of exactly x successes:
P(X = x) = C(n, x) × px × (1 − p)n−x, with C(n, x) = n! / (x!(n−x)!)
- n: number of independent trials (the sample size).
- x: a possible number of successes, from 0 to n; k is the number actually observed.
- p: probability of success on one trial. In the test it is the null value p0.
- C(n, x): the number of ways to choose which x trials are successes.
The test then forms its p-value from these probabilities:
- Upper one-sided (H1: p > p0): P(X ≥ k) = sum of P(X = x) for x from k to n.
- Lower one-sided (H1: p < p0): P(X ≤ k).
- Two-sided: the sum of P(X = x) over every outcome whose probability is no larger than P(X = k). This is the widely used “small p-values” convention. When p0 ≠ 0.5 the distribution is skewed, so the two-sided p-value is not simply twice the one-sided one.
Worked example with the arithmetic shown
Suppose the historical rate of a defect is p0 = 0.30. In a new batch, 10 of n = 20 inspected items are defective (k = 10, observed proportion 0.50). Is the new rate different from 0.30?
Step 1: the observed outcome. P(X = 10) = C(20, 10) × 0.310 × 0.710 = 184,756 × 0.0000059049 × 0.0282475 ≈ 0.0308.
Step 2: the upper tail. Probabilities for 10 to 20 successes: 0.030817 + 0.012007 + 0.003859 + 0.001018 + 0.000218 + 0.000037 + 0.000005 + 0.000001 = 0.0480. This is the one-sided p-value for H1: p > 0.30.
Step 3: the two-sided p-value. Find every outcome no more likely than P(X = 10) = 0.030817. On the high side that is 10 through 20 (0.0480, from step 2). On the low side, P(X = 3) = 0.0716 is larger, so it is excluded, but P(X = 2) = 0.027846 is smaller, so 0, 1 and 2 are included: 0.000798 + 0.006839 + 0.027846 = 0.035483. Two-sided p = 0.047962 + 0.035483 = 0.0834.
Computed with SciPy, binomtest(10, 20, 0.3) returns a p-value of 0.0834 and alternative='greater' returns 0.0480. The exact (Clopper-Pearson) 95% confidence interval for the proportion is [0.272, 0.728].
Interpretation
At α = .05 the one-sided test rejects H0 (0.0480 < .05) but the two-sided test does not (0.0834 > .05). The lesson is that the choice of alternative must be fixed before looking at the data, and a one-sided test is justified only when an effect in the other direction would be of no interest or impossible.
| Result | Reading |
|---|---|
| p ≤ α | The data are unlikely under H0; reject p = p0 at level α. |
| p > α | The null cannot be rejected at level α. This is not evidence that p equals p0; SciPy’s documentation, for instance, words a non-significant result as the null hypothesis not being rejected, never as proof that it is true. |
| CI excludes p0 | Generally consistent with rejecting H0 at the matching level. Here [0.272, 0.728] contains 0.30, in line with the two-sided result. |
The exact confidence interval and the exact test are computed by different procedures, so in edge cases they can disagree slightly. R’s documentation notes that the Clopper-Pearson interval guarantees a coverage of at least the stated confidence level and is not always the shortest. See also p-value and confidence interval.
Assumptions and common mistakes
- Two outcomes per trial, constant p (NIST), and independent trials (Microsoft’s BINOM.DIST documentation). Sampling without replacement from a small finite population breaks independence.
- Fixed n chosen in advance. Stopping when the result looks significant invalidates the stated p-value.
- Doubling a one-sided p-value when p0 ≠ 0.5 gives the wrong two-sided answer (here 2 × 0.0480 = 0.0959 versus the correct 0.0834).
- Passing proportions instead of counts. Both R and SciPy expect the number of successes k and the trials n.
- Treating a non-significant result as proof of equality.
For large samples a normal-approximation test is an alternative; for two independent groups, see the two-proportion z-test. For background on what is being estimated, see population proportion, and for single-probability calculations without a test, the binomial probability calculator.
| Situation | Test |
|---|---|
| One group, one yes/no outcome, any sample size | Exact binomial test |
| Two independent groups, comparing proportions | Two-proportion z-test |
How to report it (APA style)
Report the test name, the observed and null proportions, the exact p-value, the sidedness and an interval, following your journal’s or instructor’s style rules. A typical pattern for this data:
An exact binomial test showed that the proportion of defective items (10 of 20, .50) was not significantly different from the historical rate of .30, two-tailed p = .083, 95% CI [.27, .73].
If you pre-registered a directional hypothesis, say so and report the one-sided p (here p = .048).
How to calculate it in Excel, R or Python
Excel
Excel has no single binomial-test function, so build the p-value from BINOM.DIST(number_s, trials, probability_s, cumulative) (Microsoft Support). For the example:
One-sided (upper): =1-BINOM.DIST(9,20,0.3,TRUE) -> 0.0480
Two-sided: =1-BINOM.DIST(9,20,0.3,TRUE)+BINOM.DIST(2,20,0.3,TRUE) -> 0.0834
The lower cut-off of 2 comes from the step 3 rule above and must be recomputed for other data.
R
binom.test(10, 20, p = 0.3, alternative = "two.sided", conf.level = 0.95)
Usage per the R manual: binom.test(x, n, p = 0.5, alternative = c("two.sided","less","greater"), conf.level = 0.95). It also accepts a two-element vector of successes and failures, so binom.test(c(10, 10), p = 0.3) is equivalent.
Python
from scipy.stats import binomtest
r = binomtest(10, n=20, p=0.3, alternative='two-sided')
print(r.statistic, r.pvalue) # 0.5 0.0834...
print(r.proportion_ci(confidence_level=0.95, method='exact'))
FAQ
What is binomial test?
An exact hypothesis test of whether the probability of success in a series of yes/no trials equals a stated value, using the binomial distribution directly.
What is binomial distribution?
The distribution of the number of successes in n independent trials with a constant success probability p; mean np, standard deviation √(np(1 − p)).
How to calculate binomial distribution?
Use P(X = x) = C(n, x) px(1 − p)n−x. With n = 20, p = 0.3 and x = 6 this gives 0.1916. In Excel use BINOM.DIST(6,20,0.3,FALSE).
What is binomial probability distribution?
The full set of probabilities P(X = x) for x = 0 to n, which sum to 1.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, Binomial Distribution: itl.nist.gov/div898/handbook/eda/section3/eda366i.htm (checked 2026-10-29).
- R Documentation,
binom.test, stats package: stat.ethz.ch/R-manual/R-devel/library/stats/html/binom.test.html (checked 2026-10-29). - SciPy documentation,
scipy.stats.binomtest: docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binomtest.html (checked 2026-10-29). - Microsoft Support, BINOM.DIST function: support.microsoft.com/en-us/office/binom-dist-function-c5ae37b6-f39c-4be2-94c2-509a1480770c (checked 2026-10-29).








