Fisher's Exact Test Calculator
Enter the four cell counts of your 2×2 table and get the exact two-sided and one-sided p-values, the odds ratio with its exact confidence interval, and every table with the same margins.
| Outcome: Yes | Outcome: No | Row total | |
|---|---|---|---|
| Group 1 | 10 | ||
| Group 2 | 6 | ||
| Column total | 9 | 7 | 16 |
Exact 95% CI [1.01, 1059.64]
Calculation
Every table with the same margins
The bar chart shows the hypergeometric probability P(a) of every table with the same row and column totals. The red bar is your table; purple bars are the tables counted toward the two-sided p-value.
Fisher's exact test is the small-sample test for a 2×2 table — use it when any expected count is below 5 and the chi-square approximation breaks down. Enter the four cell counts and get the exact two-sided p-value, both one-sided p-values, the odds ratio with its exact confidence interval, and every table with the same margins.
This test is for a 2×2 table with SMALL counts — when any expected count is below 5, the chi-square approximation is unreliable and Fisher's exact test is the safe choice. For larger counts, use the chi-square test instead.
Fisher's exact test gives a p-value (is there an association?). To measure HOW STRONG the association is, use the odds ratio calculator.
How to use the Fisher's exact test calculator
- Enter the four cell counts a, b, c, d into the 2×2 grid (Group 1 / Group 2 rows; Outcome Yes / No columns). The row and column totals update as you type.
- Choose the tail: two-sided (the usual choice), or one-sided P(X ≥ a) / P(X ≤ a) if you have a directional hypothesis.
- Choose the significance level α (0.05 by default) and tick “Show mid-p value” if you want the less conservative mid-p.
- Click Calculate — the calculator also updates live as you type. Read the headline p-value, then the results grid for P(observed table), both one-sided p-values, the sample odds ratio and the conditional-MLE odds ratio with its exact confidence interval. The calculation ledger shows every step, the bar chart shows every table with the same margins, and the enumeration table lists them all.
Try it now: the drug-trial table [[8, 2], [1, 5]] is loaded by default — the two-sided p-value is 0.0350, so the association is significant at the 5% level. Click “NIST example (WE3)” to load the classic [[2, 5], [3, 2]] table from the NIST handbook.
What is Fisher's exact test?
Fisher's exact test checks whether two categorical variables are associated, using a 2×2 table. The null hypothesis H₀ is that the two variables are independent — the odds ratio is 1 and the proportion of “Yes” outcomes is the same in both groups. The alternative is that the proportions differ.
The test conditions on both margins: it treats the row totals and the column totals as fixed, and asks how likely your table is among all the tables that share those same totals. The probability of any one table comes from the hypergeometric distribution:
P(a) = C(a + c, a) × C(b + d, b) / C(N, a + b), where N = a + b + c + d.
“Exact” means the p-value is computed from that exact discrete distribution, not from a large-sample approximation such as the chi-square distribution. The test is valid at any sample size, but it is most useful exactly where the approximations fail — when counts are small. It is named after R. A. Fisher, who introduced it in the 1930s (the famous “lady tasting tea” experiment is the textbook origin story).
Fisher's exact test vs chi-square: which one do you need?
Rule of thumb: if the smallest expected count is below 5, use Fisher's exact test. If every expected count is 5 or more, the chi-square test is fine — and faster for very large tables.
| Question | Fisher's exact test | Chi-square test |
|---|---|---|
| What does it assume? | Nothing about sample size — the p-value is exact | A large-sample approximation to the χ² distribution |
| When to use it | Any expected count below 5 | All expected counts 5 or more |
| What it gives | An exact p-value | An approximate p-value |
| Large tables | Slow to enumerate (this calculator stops at N > 10,000) | Fast at any size |
| What it conditions on | Both margins fixed | Neither margin fixed |
The rule comes from Cochran (1954): the chi-square approximation is unreliable when expected counts are small, because the discrete counts are too far from the continuous χ² curve. The calculator shows the expected counts under H₀ and flags the smallest one against this rule, so you can see the decision for your own table. In the drug-trial example below, the smallest expected count is 2.625 — below 5 — so Fisher's exact test is the right choice, and the chi-square p-value (0.0134) exaggerates the evidence compared with Fisher's exact 0.0350.
If your counts are large and you want a confidence interval for the difference between two proportions rather than a p-value, use the confidence interval for the difference of two proportions calculator; to test the same difference with a z-test, use the two-proportion z-test calculator.
How the p-value is calculated
The calculator lists every table with the same margins and works out the probability of each one. For the drug-trial table below there are 7 such tables (a runs from 3 to 9). The two-sided p-value uses R's probability-ordering rule: add up the probabilities of all tables whose probability is no larger than the probability of the table you observed. The one-sided p-values are simpler: P(X ≤ a) adds the probabilities of all tables with a top-left cell no larger than yours; P(X ≥ a) adds all tables with a top-left cell no smaller than yours.
Because the distribution is discrete, the two-sided p-value is not just double the one-sided p-value — see the worked examples and the FAQs below. The optional mid-p value subtracts half of P(observed) from the two-sided p-value, which makes the test slightly less conservative; it is off by default.
Worked examples
Example 1: a drug trial
Eight of 10 patients recovered on the drug, but only 1 of 6 on placebo:
| Recovered | Not recovered | Total | |
|---|---|---|---|
| Drug | 8 | 2 | 10 |
| Placebo | 1 | 5 | 6 |
| Total | 9 | 7 | 16 |
With the margins fixed, a can be 3, 4, 5, 6, 7, 8 or 9, with probabilities 0.0105, 0.1101, 0.3304, 0.3671, 0.1573, 0.0236 and 0.0009. The observed table (a = 8) has probability 0.0236. The two-sided p-value adds the tables with probability no larger than that — a = 3, 8 and 9 — giving p = 0.0105 + 0.0236 + 0.0009 = 0.0350, so the association is significant at α = 0.05. The one-sided p-values are P(X ≥ 8) = 0.0245 and P(X ≤ 8) = 0.9991, and the mid-p value is 0.0232.
The sample odds ratio is OR = (8 × 5) / (2 × 1) = 20.0; the conditional-MLE odds ratio is 15.47, with an exact 95% confidence interval of [1.01, 1059.64]. The interval excludes 1, agreeing with the significant p-value, but it is very wide — a tiny sample can only pin the odds ratio down loosely. The expected counts under H₀ are [[5.625, 4.375], [3.375, 2.625]]; the smallest, 2.625, is below 5, so Fisher's exact test is the right test here. For comparison, the chi-square statistic (no Yates correction) is 6.1122 with p = 0.0134 — the approximation exaggerates the evidence.
Example 2: a stronger effect
Change one cell — the table [[8, 2], [1, 9]] — and the evidence strengthens: the two-sided p-value falls to 0.0055, the sample odds ratio rises to 36.0, and the conditional-MLE odds ratio is 27.33 with an exact 95% CI of [2.06, 1766.95]. For comparison, the Woolf (log-scale) 95% confidence interval for the same odds ratio is [2.72, 476.28] — the interval the odds ratio calculator reports. The exact interval is wider, as exact intervals usually are.
Example 3: the NIST example
The NIST/SEMATECH e-Handbook works this table by hand: [[2, 5], [3, 2]] (row totals 7 and 5, column totals 5 and 7, N = 12). The observed table has probability 0.2652, and the six tables have probabilities 0.0013, 0.0442, 0.2652, 0.4419, 0.2210 and 0.0265 for a = 0 to 5.
Watch the one-sided / two-sided distinction: NIST's value of 0.3106 is the one-sided p-value (0.2652 + 0.0442 + 0.0013). The calculator's two-sided p-value, by probability ordering, is 0.5581 — the sum of the probabilities of all tables with P ≤ 0.2652 (a = 0, 1, 2, 4, 5). Both numbers are correct; they answer different questions. Neither is significant at α = 0.05. The conditional-MLE odds ratio is 0.3006 with an exact 95% CI of [0.0132, 4.9227]. The chi-square statistic (no Yates) is 1.1853, p = 0.2763; with Yates's correction it is 0.2449, p = 0.6207. The smallest expected count is 2.08, below 5, so Fisher's exact test is indicated.
The odds ratio and its exact confidence interval
Fisher's exact test answers “is there an association?” — the odds ratio answers “how strong is it?” The calculator reports two versions:
- Sample odds ratio ad/bc — the plug-in estimate from your table (20.0 in Example 1). Simple, but unstable when counts are small.
- Conditional-MLE odds ratio — the value of θ that makes the expected value of a equal the observed a under Fisher's noncentral hypergeometric distribution (15.47 in Example 1). This is the odds ratio R's
fisher.testreports, and it is the natural partner for the exact test because it comes from the same conditional distribution. With small counts it is pulled toward 1 relative to ad/bc.
The confidence interval is an exact interval by Cornfield inversion: the lower end is the θ for which P(X ≥ a | θ) = 0.025, and the upper end is the θ for which P(X ≤ a | θ) = 0.025. It is guaranteed to cover at least 95% of the time, which is why it is wider than the Woolf interval from the odds ratio calculator.
Zero cells: if a cell is zero, the sample odds ratio is 0 or ∞ and the calculator says so plainly instead of hiding it. The exact confidence interval is still computed (a conditional-MLE odds ratio of 0 gives an interval [0, hi]; an infinite one gives [lo, ∞]). For a usable point estimate with a zero cell, the odds ratio calculator applies the Haldane–Anscombe correction, adding 0.5 to each cell.
How do I do Fisher's exact test in Excel?
Excel has NO built-in Fisher's exact test function. The engine for building one is HYPGEOM.DIST: =HYPGEOM.DIST(sample_s, number_sample, population_s, number_pop, FALSE) returns the hypergeometric probability of one table. To get the two-sided p-value you must sum HYPGEOM.DIST over every table with the same margins — or use the calculator above, which does the enumeration for you.
Trap — do not confuse the two Fishers: Excel's FISHER(x) is the Fisher TRANSFORMATION (atanh), NOT Fisher's exact test. Microsoft's own description says it “returns the Fisher transformation at x… Use this function to perform hypothesis testing on the correlation coefficient” — for example, =FISHER(0.75) returns 0.9729551. It has nothing to do with 2×2 tables.
Frequently asked questions
When do I use Fisher's exact test instead of chi-square?
When any expected count is below 5. The chi-square test is a large-sample approximation, and with small counts the approximation breaks down — the p-value it gives can be badly wrong (in Example 1 it gives 0.0134 where the exact answer is 0.0350). Fisher's exact test is exact at any sample size, so it is the safe choice whenever a count is small. When all expected counts are 5 or more, either test is fine.
What does “exact” mean here?
It means the p-value is computed from the exact hypergeometric distribution over all tables with the same row and column totals — no approximation, no large-sample assumption. The test conditions on both margins, which is what makes the exact calculation possible. A p-value from an exact test has the meaning it claims: the probability, under the null hypothesis of no association, of a table at least as surprising as yours.
Why is the two-sided p-value not just double the one-sided one?
Because the hypergeometric distribution is discrete and asymmetric. The two-sided p-value here is the sum of the probabilities of all tables with P ≤ P(observed) — R's probability-ordering rule — not twice the smaller tail. In the NIST example the one-sided p-value is 0.3106 but the two-sided p-value is 0.5581, not 0.6212. Doubling is a shortcut that only works for symmetric continuous distributions.
What is the conditional-MLE odds ratio, and why is it not ad/bc?
The sample odds ratio ad/bc is the plug-in estimate from your table. The conditional-MLE odds ratio is the value of θ that makes the expected value of a equal the observed a under Fisher's noncentral hypergeometric distribution — the conditional distribution the test itself uses. It is what R's fisher.test reports. With small counts it is pulled toward 1 relative to ad/bc (15.47 versus 20.0 in Example 1), and its exact confidence interval comes from inverting the test. For large samples the two agree.
What if a cell is zero?
The test still works — a table with a zero cell has a hypergeometric probability like any other, and the p-value is computed the same way. What changes is the odds ratio: the sample odds ratio is 0 or ∞, and the calculator states that plainly. The exact confidence interval is still computed (a conditional-MLE odds ratio of 0 gives [0, hi]; an infinite one gives [lo, ∞]). For a usable odds-ratio estimate with a zero cell, the odds ratio calculator applies the Haldane–Anscombe correction, adding 0.5 to each cell.
Why is the confidence interval so wide?
Because the sample is tiny. An exact interval is honest about how little information a 2×2 table with 16 people contains: in Example 1 the interval is [1.01, 1059.64]. It excludes 1, which agrees with the significant p-value, but the upper end is huge because the data cannot rule out a very large odds ratio. Larger samples narrow the interval. The width is a property of the data, not a bug in the calculator.
Source: Worked Example 3 is the NIST/SEMATECH e-Handbook example in “How can we determine whether two processes produce the same proportion of defectives?” (7.3.3), which works the same table by hand. The method follows the NIST Dataplot reference “Fisher Exact Test”, which computes it with ACM Algorithm 643 (the FEXACT routine of Mehta and Patel).
See all 67 free statistics tools on Empirical Rule Calculators.
Next steps
🧮● Live
Chi-Square Test Calculator
Test independence on larger tables — the large-count companion.CalculatorTry Calculator →
🧮● Live
Odds Ratio Calculator
Measure how strong the association is — OR with a confidence interval.CalculatorTry Calculator →
More Tools to Explore
Keep going with the calculators that pair with Fisher's exact test — chi-square, odds ratios, two-proportion tests and intervals.
Chi-Square Test Calculator
Test independence on larger tables — the large-count companion.
Odds Ratio Calculator
Measure how strong the association is — OR with a confidence interval.
Two-Proportion Z-Test Calculator
Compare two percentages with a pooled z-test — the 2×2 test for large counts.
P-Value Calculator from Z-Score
Turn any z-score into a one- or two-tailed p-value.
CI for Difference of Two Proportions
Build a confidence interval for p₁−p₂ — the interval version of this test.
Normal Distribution Calculator
Find any normal probability or quantile, with a shaded bell curve.
Explore All Tools →
Browse all 67 free statistics tools — every calculator on this site in one place.