induwara.lk
induwara.lkStatistics · Education

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.

By Induwara AshinsanaUpdated Jul 9, 2026
Fisher's exact test
Hypergeometric · exact
Your 2×2 table (enter the four counts)
Examples
Alternative hypothesis

Between 0 and 1

Two-sided p-value
0.03497
One-sided (greater)
0.02448
One-sided (less)
0.9991
Point probability
0.0236
P(observed table)
Odds ratio
20
(a·d)/(b·c), sample estimate
Relative risk
4.8
row-1 outcome, sample estimate
p = 0.03497 < α = 0.05 reject the null hypothesis of independence. The association is statistically significant at this level (two-sided).
YesNoTotal
Group A8210
Group B156
Total9716
Which test should I use?

The smallest expected count in your table is 2.63. Because it is below 5, the chi-square approximation is unreliable — Fisher's exact test (the p-values above) is the correct choice.

Verification: all 7possible tables' probabilities sum to 1.000000 (should be 1.000000), and the observed point probability is cross-checked with a second, independent factorial computation.

Sources: hypergeometric p-value per the NIST/SEMATECH e-Handbook §3.3; two-sided convention matches R's stats::fisher.test. Results computed entirely in your browser — nothing is uploaded.

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

Study-app pilot (16 students) — significant

a=8, b=2, c=1, d=5

  1. 8 of 10 app users passed; 1 of 6 non-users passed.
  2. Margins: rows 10 and 6, columns 9 and 7, n = 16, C(16,9) = 11,440.
  3. Observed table probability P(a=8) = 270/11,440 = 0.02360.
  4. Two-sided p (all tables with P ≤ 270/11,440) = 400/11,440 = 0.03497.
  5. Odds ratio = (8·5)/(2·1) = 20. At α = 0.05: p < 0.05 → significant.

Vaccine pilot (n=20) — strongly protective

a=1, b=9, c=9, d=1

  1. 1 of 10 vaccinated infected vs 9 of 10 unvaccinated infected.
  2. Margins: rows 10 and 10, columns 10 and 10, n = 20, C(20,10) = 184,756.
  3. One-sided less (a ≤ 1) = 101/184,756 = 0.0005467.
  4. Two-sided = 202/184,756 = 0.001093 (matches R fisher.test).
  5. Odds ratio = (1·1)/(9·9) = 0.0123. At α = 0.05: p < 0.05 → significant.

Balanced trial (n=8) — not significant

a=3, b=1, c=1, d=3

  1. Small 8-subject table with a 3-vs-1 split each way.
  2. Margins all 4, n = 8, C(8,4) = 70. P(a=3) = 16/70 = 0.2286.
  3. Two-sided = 34/70 = 0.4857 (the a=2 table at 36/70 is more likely, so excluded).
  4. Odds ratio = (3·3)/(1·1) = 9 — but the sample is tiny.
  5. At α = 0.05: p = 0.486 ≥ 0.05 → fail to reject; not significant despite OR = 9.

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.