What Fisher's exact test does
Fisher's exact test measures whether two categorical variables in a 2×2 contingency table are associated. You arrange your data as four counts — cells a, b, c and d — and the test returns the exact probability of seeing a table at least as extreme as yours if the two variables were in fact independent. Unlike the chi-square test, it makes no large-sample approximation, so it is valid even when the counts are tiny.
The classic illustration is R. A. Fisher's "lady tasting tea." A woman claimed she could tell whether milk or tea was poured into the cup first. Given 8 cups — 4 milk-first and 4 tea-first — she correctly identified 3 of the 4 milk-first cups, giving the table below. Fisher's test asks: how likely is that hit rate by pure guessing?
The 2×2 table and the formula
Label the table so that a and b are the top row, c and d the bottom row:
| Column 1 | Column 2 | Row total | |
|---|---|---|---|
| Row 1 | a | b | a+b |
| Row 2 | c | d | c+d |
| Col total | a+c | b+d | n |
With all four margins (row totals and column totals) held fixed, the probability of any particular table follows the hypergeometric distribution:
P = [ (a+b)! × (c+d)! × (a+c)! × (b+d)! ] / [ a! × b! × c! × d! × n! ]
To get the two-tailed p-value, the calculator enumerates every possible table that keeps the same margins, computes each table's probability, and adds up the probabilities of all tables that are as likely or less likely than your observed table. The one-tailed p-value sums the probabilities in a single direction (the tail your table falls in) and is always the smaller of the two one-sided sums reported here.
A worked example: the lady tasting tea
Her result is a = 3, b = 1, c = 1, d = 3 (3 milk-first cups called correctly, 1 missed; 1 tea-first cup wrongly called milk-first, 3 correct). The probability of exactly this table is 0.2286. Summing the equally-or-less-likely tables gives a two-tailed p-value of 0.4857 and a one-tailed p-value of 0.2429. Because 0.4857 is far above 0.05, guessing 3 of 4 is not strong enough evidence of real ability. The sample odds ratio here is (3×3)/(1×1) = 9.
The odds ratio
Alongside the p-value the calculator reports the sample odds ratio, (a×d)/(b×c). It summarizes the direction and strength of the association: 1 means no association, values above 1 a positive association, and values below 1 a negative one. Note this is the simple cross-product odds ratio; statistical software such as R reports a conditional maximum-likelihood estimate instead, which can differ slightly. If b or c is zero the odds ratio is infinite, and if a or d is zero it is zero, so it is shown as undefined in those cases.
When to use it
- Any expected cell count is small — the usual trigger is an expected count below 5, where the chi-square approximation is unreliable.
- Total sample size is small (often under about 20–40), a common situation in early-stage clinical, laboratory, or A/B pilot data.
- You have exactly two rows and two columns of counts. For larger tables use the Freeman-Halton extension of Fisher's test instead.