Fisher's Exact Test Calculator (2×2)
Enter the four counts of a 2×2 contingency table to get the exact two-sided and one-sided p-values, the sample odds ratio and relative risk, and a plain-English verdict. It is the small-sample alternative to the chi-square test — valid when expected counts fall below 5. Runs in your browser, no signup, sources cited below.
How it works
Fisher's exact test asks a precise question about a 2×2 table: holding the row totals and column totals fixed at what you observed, how likely is a split of the counts at least as extreme as yours, if the row and column variables were actually independent? Because it works out that probability exactly rather than approximating it, the test is valid for the small samples where the chi-square test breaks down.
For a table with cells a, b, c, d and fixed margins (row totals a+b and c+d, column totals a+c and b+d, grand total n), the probability of any particular table follows the hypergeometric distribution:
P = ( (a+b)! · (c+d)! · (a+c)! · (b+d)! ) / ( a! · b! · c! · d! · n! )
Once the four margins are fixed, only cell a is free to vary; the other three are determined by subtraction. Cell a ranges from max(0, (a+c)−(c+d)) up to min(a+b, a+c). The tool enumerates every table in that range and its probability. To avoid factorial overflow the factorials are computed in log space with a Lanczos log-gamma function, so ln(k!) = lnΓ(k+1), then each probability is recovered with exp.
The three p-values come straight from that list of tables:
- One-sided “greater” — the sum of probabilities of all tables whose cell a is at least the observed value (evidence the odds ratio is above 1).
- One-sided “less” — the sum for all tables whose cell a is at most the observed value.
- Two-sided— the sum over every table whose own probability is no greater than the observed table's (with a tiny tolerance for floating-point ties). This is the default and it matches the convention used by R's
stats::fisher.test.
Alongside the p-values the tool reports the sample odds ratio = (a·d)/(b·c) and the relative risk of the row-1 outcome = [a/(a+b)] ÷ [c/(c+d)], both as sample estimates. It also computes the expected count of every cell under independence, E = (row total × column total) / n, and flags whether the smallest is below 5 — the standard rule for preferring Fisher's exact test over chi-square. As a self-check, the probabilities of all enumerated tables sum to 1, and the observed table's probability is confirmed with independent exact rational arithmetic.
Worked examples
Frequently asked questions
Sources & references
- NIST/SEMATECH e-Handbook of Statistical Methods, §3.3 — Contingency tables & exact inference
- R stats::fisher.test documentation — the two-sided convention replicated here
- R. A. Fisher (1922/1934) — the exact test on fixed marginal totals (Statistical Methods for Research Workers)
The hypergeometric formula, the log-gamma enumeration and the two-sided convention were last cross-checked against R's fisher.test on 2026-07-09. The worked examples above reproduce those results to at least four significant figures.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.