Fisher’s Exact Test Calculator
Test whether two categorical variables are associated in a 2×2 contingency table — the right choice when your sample is small or cells are sparse. Enter your four counts to get exact one- and two-tailed p-values, the odds ratio, relative risk, and a clear significance decision, with the hypergeometric working shown.
Exact hypergeometric math · Reviewed July 2026 · Method follows the NIST e-Handbook on comparing two proportions
Enter Your 2×2 Table
Two-tailed tests for association in either direction — the usual default for contingency tables.
Your Result
Contingency Mosaic
Cell proportions across the two groups
| Measure | Value |
|---|
What Is Fisher’s Exact Test?
Fisher’s exact test is a statistical test that determines whether two categorical variables are associated, using a 2×2 contingency table. It answers a focused question: given the counts in your table, is the pattern strong enough to conclude the two variables are related — or could it easily have arisen by chance? Because it computes the probability exactly rather than through an approximation, it stays valid no matter how small your sample is. That’s what makes it the go-to test for tiny or sparse datasets where other methods break down.
The test earns the word “exact” honestly. Instead of relying on a large-sample approximation like the chi-square test does, it uses the hypergeometric distribution to calculate the precise probability of your observed table — and every table more extreme than it — assuming the two variables are independent. Sum those probabilities and you have your p-value, computed to the last decimal with no approximation error.
The lady tasting tea
Fisher’s exact test was born from one of statistics’ most charming stories. In the 1920s, Muriel Bristol claimed she could taste whether milk or tea had been poured into the cup first. Ronald Fisher, skeptical, designed an experiment: eight cups, four poured each way, presented in random order. Because the sample was so small, no approximate test would do — so Fisher worked out the exact probability that she could get her guesses right by luck alone. That calculation became the test we still use today, and it’s why the method is tailor-made for small samples.
The Formula: Hypergeometric Probability
For a 2×2 table with cells a, b, c, and d, and fixed row and column totals, the probability of that exact table under independence is:
P = (a+b)! (c+d)! (a+c)! (b+d)! / ( n! · a! · b! · c! · d! )
where n = a + b + c + d is the grand total. To get the p-value, the test doesn’t stop at your table — it computes this probability for every possible table with the same margins, then adds up the probabilities of all tables at least as extreme as yours. This calculator does that enumeration for you and reports the result, using logarithms of factorials internally so the math stays accurate even with larger counts.
One-tailed vs. two-tailed
The one-tailed p-value sums the probabilities of tables at least as extreme in a single direction — useful when you have a directional hypothesis (for example, the treatment can only help). The two-tailed p-value, the standard default, sums the probabilities of all tables whose probability is no greater than your observed table’s, capturing extreme deviations in either direction.
When to Use Fisher’s Exact Test (vs. Chi-Square)
Fisher’s exact test and the chi-square test of independence answer the same question — is there an association in a contingency table? — but they suit different situations. The deciding factor is sample size and expected cell counts.
| Use Fisher’s exact test when… | Use chi-square when… |
|---|---|
| Any expected cell count is below 5 | All expected cell counts are 5 or more |
| Total sample size is small (roughly n < 20–40) | The sample is large |
| You need an exact, not approximate, p-value | An approximate p-value is acceptable |
| Cells contain rare events or zeros | Counts are comfortably large in every cell |
The reason comes down to how each test works. The chi-square test relies on an approximation that only becomes accurate as counts grow; with small cells it can give a misleadingly small p-value. Fisher’s exact test has no such weakness — it’s always valid. As samples get large, the two converge and give practically the same answer, at which point chi-square is simply faster to compute. If your table qualifies for chi-square instead, our P-Value Calculator computes chi-square tail probabilities directly.
How to Interpret Fisher’s Exact Test Results
Reading the output comes down to three numbers this calculator provides:
- The p-value. Compare it to your significance level (α, usually 0.05). If p ≤ α, there’s a statistically significant association between the two variables and you reject the null hypothesis of independence. If p > α, you fail to reject it — the data doesn’t show a significant association.
- The odds ratio (OR). Calculated as (a×d)/(b×c), it measures the strength and direction of the association. OR > 1 means the exposure is linked to higher odds of the outcome; OR < 1 means lower odds; OR = 1 means no association.
- The relative risk (RR). The ratio of outcome rates between the two groups, an intuitive way to express how much more (or less) likely the outcome is in one group.
Good practice is to report all three together — for example, “the treatment group had a significantly higher recovery rate (Fisher’s exact test, p = 0.015; OR = 5.4).” The p-value tells you whether the association is real; the odds ratio and relative risk tell you how big it is.
A Worked Example
Suppose a small pilot trial gives 10 patients a treatment and 10 a placebo. Among the treated, 7 recover and 3 don’t; among the placebo group, 3 recover and 7 don’t. Your 2×2 table is [[7, 3], [3, 7]]. With such small numbers, chi-square isn’t trustworthy — so Fisher’s exact test is the right call. The calculator returns the exact p-value and an odds ratio of about 5.4, telling you both whether the difference is significant and how large the effect appears. Try the “example” button above to load exactly this table.
Assumptions and Limitations
- Categorical counts: the four cells must be whole-number frequencies, not percentages or averages.
- Independent observations: each subject contributes to exactly one cell.
- 2×2 design: the classic test handles two rows and two columns; larger tables need the Freeman–Halton extension.
- Fixed margins: the exact p-value is computed treating the row and column totals as fixed, which is the standard formulation.
Fisher’s exact test tells you whether an association exists, but not the plausible range of the effect — pair it with a Confidence Interval Calculator for the odds ratio to communicate precision, and see our statistics calculators hub for the full toolkit.
Frequently Asked Questions
Fisher’s exact test determines whether two categorical variables are associated in a 2×2 contingency table. It’s used to compare a binary outcome between two groups — for example, whether a treatment produces a higher recovery rate than a placebo, or whether an outcome differs by gender. Because it computes an exact p-value from the hypergeometric distribution, it stays valid for small samples where the chi-square test’s approximation breaks down.
Use Fisher’s exact test when any expected cell count is below 5, when the total sample size is small (roughly under 20–40), or when you need an exact rather than approximate p-value. Use the chi-square test of independence when all expected cell counts are 5 or more and the sample is large. As samples grow, the two tests converge and give nearly identical results, so chi-square is chosen mainly for its computational speed on large tables.
Compare the p-value to your significance level, usually 0.05. If the p-value is less than or equal to 0.05, there’s a statistically significant association between the two variables, so you reject the null hypothesis of independence. If it’s greater than 0.05, you fail to reject the null hypothesis, meaning the data doesn’t show a significant association. Report the odds ratio alongside the p-value to convey the size of the effect, not just its significance.
The odds ratio, calculated as (a×d)/(b×c) from the table cells, measures the strength and direction of the association. An odds ratio greater than 1 means the exposure or group is associated with higher odds of the outcome; less than 1 means lower odds; and exactly 1 means no association. For example, an odds ratio of 5 means the odds of the outcome are five times higher in the first group. It complements the p-value by showing effect size.
It’s called exact because it computes the precise probability of the observed data using the hypergeometric distribution, rather than relying on an approximation that only becomes accurate as the sample grows. The chi-square test, by contrast, uses a large-sample approximation that can be inaccurate with small counts. Fisher’s exact test enumerates every possible table with the same margins and sums the exact probabilities, so its p-value is valid for any sample size.
The classic Fisher’s exact test is designed for 2×2 tables. For larger contingency tables, such as 2×3 or 3×3, the Freeman–Halton extension generalizes the same exact approach. However, the computation becomes intensive as the table grows, so software is typically used. This calculator focuses on the standard and most common 2×2 case, which covers the large majority of practical applications comparing two groups on a binary outcome.
Methodology & formulas used
This calculator performs Fisher’s exact test on a 2×2 table, reviewed July 2026. All computation runs locally in your browser; your data is never uploaded.
- Table probability: the hypergeometric probability P = (a+b)!(c+d)!(a+c)!(b+d)! / (n! a! b! c! d!), computed via log-factorials (Lanczos gammaln) for numerical stability.
- Two-tailed p-value: the sum of probabilities of all tables (with the same margins) whose probability is less than or equal to the observed table’s probability — the standard method used by R’s fisher.test.
- One-tailed p-values: the cumulative probability of tables at least as extreme as observed in the chosen direction (left or right).
- Odds ratio: the sample odds ratio (a×d)/(b×c).
- Relative risk: [a/(a+b)] / [c/(c+d)], the ratio of outcome rates between the two rows.
- Decision: the result is statistically significant when p ≤ α.
The p-value is computed treating both sets of marginal totals as fixed, the standard conditional formulation. Cells must be non-negative integers. The sample odds ratio and relative risk are undefined when a bordering cell is zero; the exact p-value remains valid in that case.
References
- NIST/SEMATECH e-Handbook of Statistical Methods. Comparing Two Proportions. itl.nist.gov
- Fisher, R.A. (1935). The Design of Experiments — the “lady tasting tea” and the exact test. Lady tasting tea overview
- Wikipedia. Fisher’s exact test — hypergeometric formulation and interpretation. en.wikipedia.org
