Bell Statistics

Fisher's exact test calculator

Enter the four counts of a 2×2 table and get exact one- and two-sided p-values plus the odds ratio. Nothing here is approximated: the p-value is summed from the hypergeometric distribution itself, which is why this is the test to use when a cell holds single digits and [the chi-square approximation](/calculators/chi-square-test) has stopped being trustworthy.

Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

Calculator

A proportion, so 0.5 is 50%.

The smallest difference worth detecting.

n₂ ÷ n₁. 1 is an even split.

Required sample size per group
Per group33
Group 233
Total66
Achieved powerAt the whole-number sample above.81.0%
Difference in ratesGroup 2 against group 1, as a share of group 1's rate.-70.0%

Plan for 33 in each group, 66 in all, to separate 50.0% from 15.0% about 81.0% of the time. Treat that as a floor rather than the answer: it is the continuity-corrected normal approximation, and Fisher's test is conservative, so the exact requirement is a little higher. Note how fast the cost climbs as the two rates converge — a gap of a few points needs hundreds per group, not dozens — which is the honest reason a small table can only ever settle a large difference.

  • This sample size is the continuity-corrected normal approximation, not exact unconditional power. Fisher's test is conservative, so treat it as a lower bound and round up if the study is small.
Sample size per group against statistical powerReaching 0.1% power takes 1 per group and 99.0% takes 66; the 80.0% target is met at 33.1020304050600%25%50%75%100%PowerSample size — per group80.0% → 33

Drag the dashed line — or focus it and use the arrow keys — to change the target power and resize the study.

Show these numbers as a table
Power at each sample size per group
PowerSample size
0.1%1
23.7%11
55.7%21
77.8%31
90.0%41
95.8%51
98.3%61
Required sample per group against difference in ratesDetecting 2.0% takes 9,906 and 49.5% takes 15. At the 35.0% currently entered it is 33 — the requirement falls roughly as the square of the effect.1001,00010.0%20.0%30.0%40.0%Difference in ratesRequired sample per group (log scale)35.0% → 33

Drag the dashed line — or focus it and use the arrow keys — to change difference in rates.

Show these numbers as a table
Required sample per group against difference in rates
Difference in ratesRequired sample per group
2.0%9,906
6.9%855
11.7%297
16.6%149
21.5%89
26.4%59
31.2%42
36.1%31
41.0%23
45.8%18

When to use it

Use Fisher's exact test on a 2×2 table whenever the counts are small enough that you would not trust a normal or chi-square approximation. The usual trigger is an expected count below about five, but the honest rule is simpler: if the answer changes depending on which approximation you picked, stop approximating. Enterprise pilots, beta cohorts, fraud investigations — anything where the interesting cell holds four rather than four thousand is this test's territory, and it is territory where most online calculators quietly return a chi-square p-value instead.

It is also perfectly valid on large tables; the reason it is not the default there is computational rather than statistical. On a conversion test of tens of thousands, the two-proportion z-test gives essentially the same answer far faster, and its Newcombe interval on the difference is more useful than an odds ratio.

Two neighbouring designs need different tests. If the same units contribute to both rows — the same users surveyed before and after, the same accounts audited twice — the table is paired and Fisher's test is wrong; use McNemar's test, which conditions on the discordant pairs. More than two rows or columns wants the chi-square test, with the small-count warning taken seriously. And for a bound on one group's rate rather than a comparison, the proportion confidence interval calculator is the right tool — at counts this small, Wilson or Clopper-Pearson rather than anything Wald-shaped.

Assumptions

Fisher's exact test asks less of your data than any of its neighbours, which is the point of it. What it does ask, it asks strictly.

  • Every observation is independent and falls in exactly one of the four cells. Small samples make this harder, not easier: with thirty accounts it is tempting to include the same customer's two subsidiaries, and at that n a single duplicated unit moves the p-value visibly.
  • Both variables are genuinely binary and were defined before the data. Dichotomising a continuous outcome at the cut point that maximises the difference is a search dressed up as a test, and far more damaging at small n than large.
  • No distributional assumption at all. Nothing to check about normality, variance or expected counts — the null distribution is the hypergeometric, computed exactly. That is the whole reason to use it, and why the small-count warnings that apply to chi-square do not arise here.
  • The margins are treated as fixed. This is the assumption people argue about. Conditioning on both sets of totals is what makes the calculation exact, and also why the test is conservative: discreteness leaves the achieved type-I error below the nominal 5% rather than at it. Fisher errs towards not finding things — the safer direction for a pilot, but worth knowing before you read a p of 0.06 as an absence of effect.

How the calculation works

With all four margins held fixed, the null distribution of one cell is hypergeometric — so the probability of every table that could have produced those margins is computable, and the p-value is the sum of those at least as extreme as yours. Probabilities are accumulated in logs via log-gamma rather than by evaluating factorials, so totals in the thousands do not overflow. The two-sided p-value uses the minimum-likelihood convention: every table no more probable than the observed one is counted, which is what R's fisher.test does. That is worth stating plainly, because the common alternative — doubling the one-sided p — gives a different number whenever the margins are unbalanced, and the two can land on opposite sides of 0.05. If either convention leaves you near the threshold, the useful response is not to pick the friendlier one but to accept that a table this small cannot settle the question, and to [size the follow-up properly](/calculators/ab-test-sample-size).

Probability of one table
P(a) = C(a+b, a)·C(c+d, c) / C(n, a+c) with margins a+b, c+d, a+c, b+d fixed

The hypergeometric probability of exactly a in the top-left cell: the chance of drawing a successes when a+c items are taken without replacement from n containing a+b of one row type.

One-sided p-value
p₊ = Σ_{k ≥ a} P(k) or p₋ = Σ_{k ≤ a} P(k)

The tail in the direction you nominated in advance. Both are reported; choosing the smaller of them after the fact roughly doubles your real false-positive rate.

Two-sided p-value (minimum likelihood)
p = Σ { P(k) : P(k) ≤ P(a)·(1 + ε) }

Summed over every attainable table no more probable than the one observed, with a tiny relative tolerance ε so floating-point noise does not drop a table that ties with yours. Equals 2·p₊ only when the null distribution is symmetric.

Computation in logs
log P(k) = log C(a+b, k) + log C(c+d, a+c−k) − log C(n, a+c), log C(n, k) = lnΓ(n+1) − lnΓ(k+1) − lnΓ(n−k+1)

Every term is accumulated as a log and exponentiated once, so a table of a few thousand is as safe to compute as one of thirty. Naive factorials overflow a double at 171.

Odds ratio
OR = (a·d) / (b·c)

The sample odds ratio, undefined when b or c is zero. The conditional maximum-likelihood estimate R reports is shrunk slightly towards 1 and is what the exact interval is built around, so a small gap between the two figures is expected rather than a bug.

Worked example

A B2B client ran a hands-on onboarding pilot. Sixteen new accounts got the guided programme and eight reached the activation milestone within 30 days; the twenty left on self-serve produced three. That is 50% against 15%, which looks decisive — but the whole study is thirty-six accounts.

Guided onboarding
8 activated, 8 not (n = 16)
Self-serve
3 activated, 17 not (n = 20)
Alternative
Two-sided
Significance level (α)
0.05

Two-sided exact p = 0.034; one-sided p = 0.028. Sample odds ratio 5.67, conditional maximum-likelihood estimate 5.37. For comparison, doubling the one-sided p gives 0.057, Pearson chi-square gives 0.023 and the Yates-corrected chi-square gives 0.057.

Four defensible procedures on one table give 0.023, 0.034, 0.057 and 0.057 — two below the conventional threshold and two above. That spread is the real finding: at thirty-six accounts, "is this significant?" depends more on the convention you chose than on what the accounts did. Report the exact two-sided 0.034, because it is computed from the hypergeometric rather than approximated and minimum likelihood is what published analyses mean. But note what the interval does with the same data: an exact conditional 95% interval on this odds ratio runs from just under 1 to around 40. The pilot is compatible with the programme doing almost nothing and with it multiplying the odds of activation many times over, and no reading of the p-value narrows that.

Interpreting the output

Lead with the interval on the odds ratio, not the p-value. Small tables produce intervals so wide that the significance verdict is nearly beside the point, and quoting an odds ratio of 5.7 without the range around it is the most misleading thing you can do with this test. A ratio spanning roughly 1 to 40 supports "probably helps, magnitude unknown" and nothing stronger — a legitimate conclusion for a pilot, provided it is stated rather than dressed up.

Expect exact tests to feel stingy. The attainable p-values form a discrete set and the achieved type-I error usually sits below the nominal 5%, so Fisher rejects slightly less often than a perfectly calibrated test would — which is why a striking table can still return 0.06. That is a known property, not a flaw to be fixed by switching to whichever method gives a smaller number.

Do not read the odds ratio as a risk ratio. With outcomes as common as those above the two diverge sharply: odds five and a half times higher is an activation rate a little over three times higher, and stakeholders will hear the first number as the second. If the absolute difference is what matters — as it usually is commercially — report the two rates and the gap between them, and use the proportion confidence interval calculator for a bound on each arm.

Finally, treat a small significant table as a reason to run a real test, not a substitute for one. Effects estimated from tiny samples that cleared a threshold are systematically overstated, which is much of why the uplift in a test often differs from what shows up afterwards. Halve your expectations and size the confirmatory run against the smallest effect worth having — the trade our experimentation work spends most of its time on.

Frequently asked questions

Why does my two-sided p-value differ from another calculator's?
Almost certainly because the other tool doubles the one-sided p-value and this one does not. There is no single agreed definition of a two-sided p-value for a discrete asymmetric distribution. The minimum-likelihood convention used here sums the probability of every table no more likely than yours, which is what R's fisher.test reports and what most published analyses mean by Fisher's exact test. Doubling the one-sided tail is the other common choice. When the row totals are unbalanced the two disagree, occasionally on opposite sides of 0.05 — which is a good reason to report which convention you used.
When should I use this instead of a chi-square test?
Whenever any expected count in the 2x2 table falls below about five, and whenever you would rather not think about it. Fisher's test is valid at every sample size, so nothing is lost by defaulting to it on a 2x2 table other than a small amount of computation and a slight conservatism. Chi-square earns its place on larger tables, where enumerating every possible arrangement is not practical, and on very large 2x2 tables where the answers coincide anyway.
One of my cells is zero. Is the test still valid?
The test is fine — a zero cell is a perfectly ordinary table and the hypergeometric handles it without adjustment. The odds ratio is what breaks: with a zero in the b or c position the sample ratio is infinite, and with a zero in a or d it is zero. The conditional maximum-likelihood estimate behaves better, and the exact interval remains finite at one end. Reporting the two raw rates alongside is the practical answer; adding 0.5 to every cell is a common patch but it changes the estimate and is not needed for the p-value.
Is Fisher's exact test too conservative?
Somewhat, and this is a genuine and long-running debate. Conditioning on both margins makes the calculation exact but means the attainable p-values are discrete, so the real rejection rate at a nominal 5% is typically below 5%. Alternatives such as Barnard's test or a mid-p adjustment recover some power. For most applied work the conservatism is a fair price for not having to defend an approximation on a table of thirty, but if you are near the threshold and the decision is expensive, it is worth knowing that the test is leaning against you rather than towards you.
How do I plan a sample size for a small-table study?
Start from the two rates you want to distinguish and size it as an ordinary two-proportion comparison, then treat that as a floor, because the exact test's discreteness costs a little power on top. The result is usually sobering: telling a 50% rate apart from a 15% rate at 80% power needs roughly thirty per group, while telling 20% apart from 15% needs around nine hundred. If the honest number is out of reach, run the pilot as a pilot — to estimate the effect and check feasibility — rather than as a test that will be read as conclusive.

Related calculators

  • Chi-square test

    Test a contingency table of counts for association — any number of rows and columns.

  • A/B test sample size

    Size a two-proportion experiment before you launch, then read the lift and its interval once it lands.

  • Proportion confidence interval

    A defensible interval around one rate — Wilson, Agresti-Coull, Jeffreys and Clopper-Pearson, side by side.

Terms on this page

  • Sample ratio mismatch

    The split is wrong, so the randomisation is broken — the cheapest and most decisive check you can run.

Talk to the people who build these for a living

We work with the sample you actually have, and say plainly what it can and cannot settle. A/B Testing

References

  • Fisher, R. A. (1935). The logic of inductive inference. Journal of the Royal Statistical Society, 98(1), 39-82.
  • Agresti, A. (1992). A survey of exact inference for contingency tables. Statistical Science, 7(1), 131-153.
  • Agresti, A. (2013). Categorical Data Analysis (3rd ed.). Wiley.