The guide
Fisher's exact test counts every possible table, and two-sided does not mean double
With the row and column totals fixed, a 2 by 2 table has a hypergeometric law, so a p-value can be summed exactly. The two-sided value is a sum over tables, not twice the one-sided one.
- 1 in 70 chance of naming all four cups by luck
- 17/70 one-sided p-value of the tea table 3, 1, 1, 3
- 0.034965 exact two-sided p-value of the table 8, 2, 1, 5
- 0.048951 what doubling the one-sided value would claim
- 10,001 tables the most this tool lists
Read the full guide Fold the guide
Eight cups of tea
A woman says she can taste whether the milk or the tea went into a cup first. How many cups, and how many right answers, would make you believe her?
The story is told on the page for the lady tasting tea. The woman was the phycologist Muriel Bristol, and the statistician Ronald Fisher is said to have devised his test after her claim. Her future husband, William Roach, suggested eight cups, four prepared each way, served in random order, with the taster told that four of each kind were there. Under the null hypothesis that she cannot tell the cups apart, her four picks are a random choice of four cups from eight. There are 70 ways to choose them. She can have none, one, two, three or all four picks right in 1, 16, 36, 16 and 1 of those ways.
That makes the table of what she said against what was true a small, complete calculation. If she names all four cups correctly, luck explains it with probability 1 in 70, about 1.4 percent. If she gets three of four right, the chance of doing at least that well by luck is 17/70, about 24.3 percent, which is far from convincing.
Notice the difference between two numbers here. The table with three right has probability 16/70, or 0.228571. The p-value for that result is 17/70, or 0.242857, because it also counts the one more extreme table, the one with four right. A p-value is a tail, never the probability of the single table you saw.
Why the margins make it hypergeometric
Write the four counts as a, b, c and d, with a and b in the first row. The row totals are a + b and c + d, the column totals a + c and b + d, and n is the grand total. Fisher’s insight was to hold those totals fixed and ask how the counts could be arranged inside them.
Once the totals are fixed, one cell decides the rest. If you know a, then b, c and d follow by subtraction. So the whole question becomes how likely each value of a is, and the answer is a hypergeometric law: draw a + c items without replacement from n items, of which a + b are of the first kind, and ask how many of the first kind you get.
The probability of a table is C(a + b, a) times C(c + d, c), divided by C(n, a + c), where C(m, k) counts the ways to choose k things from m. The page on Fisher’s test works the table 1, 9, 11, 3 this way and gets about 0.001346076. Adding the one more extreme table, 0, 10, 12, 2, with about 0.000033652, gives a one-sided p-value of about 0.001379728.
Why not use a chi-squared test? Because that test compares counts with expected counts through a sum of squared gaps, and the chi-squared curve is an approximation that improves as the table fills up. A common rule asks for an expected count of at least 5 in every cell of a 2 by 2 table. Tea tasting has expected counts of 2. On small, sparse or lopsided tables the exact and approximate p-values can differ enough to point in opposite directions.
The exact test has its own condition. It assumes the margins were fixed by the design, as they were with the tea cups. When the totals were free to vary, which the Wikipedia page calls rare in the setting the test assumes, the test tends to be conservative: it rejects less often than its stated level. That is a reason to know how your counts were collected, not a reason to reach for the approximation.
Why two-sided does not mean double
For a one-sided test the tail is easy. The less p-value adds the probabilities of every table with the top-left count at most the observed one, and the greater p-value adds those with a count at least as large. The two-sided case needs a rule for which tables on the other side count as equally extreme.
The rule used by R and documented by SciPy is to add the probability of every table whose probability is less than or equal to that of the observed table. The two tails need not be mirror images, so the sum can pick up a different number of tables on each side. This tool compares probabilities as exact whole-number ratios, so two tables that are exactly as likely as each other are treated as equal, with no tolerance.
Take the table 8, 2, 1, 5. Its totals are 10 and 6 for the rows and 9 and 7 for the columns, so the top-left count runs from 3 to 9 and there are seven tables. Over a common denominator of 11,440 their weights are 120, 1260, 3780, 4200, 1800, 270 and 10. The observed table has 270, so its probability is 0.023601.
The greater p-value adds 270 and the 10 beyond it: 280 over 11,440, or 0.024476. The two-sided value also admits the table with count 3, whose weight of 120 is below 270, but not the table with 1260. That gives 400 over 11,440, an exact two-sided p-value of 0.034965. Doubling the one-sided value would claim 0.048951. That is about 40 percent too large, and on another table it could move a result from one side of a threshold to the other. The Wikipedia page says the two-sided value is twice the one-sided value for its worked example, but that in general the two can differ substantially for small counts.
They can also agree. For the table 6, 0, 3, 9 the table at the opposite end, 0, 6, 9, 3, is exactly as likely as the observed one, with 220 of the 48,620 arrangements each, so summing gives the same number as doubling. Exact comparison matters here: a tolerance could include or drop that tie by accident. The rule is a sum over tables, and sometimes the sum happens to look like doubling, which is why the shortcut survives.
What the odds ratio estimates, and what the test cannot do
The odds ratio compares the odds of the first outcome in the two rows. From the table it is a times d, divided by b times c. A value of 1 means the rows have the same odds, and the ratio is not defined when b times c is zero. It is symmetric in the two events and says nothing about which one causes the other.
There are two ways to estimate it. The sample odds ratio is simply ad over bc. The conditional estimate uses the same fixed margins as the test. It is the odds ratio under which the average top-left count of the noncentral hypergeometric law, a version of the law where each row has a weight, equals the count you observed. This tool finds it by bisection.
For the tea table the sample odds ratio is 9 and the conditional estimate is about 6.4083. The exact 95 percent interval runs from about 0.2117 to 626.2435. Eight cups cannot pin the ratio down, and an interval that wide is the honest answer. Each tail holds at most 2.5 percent, the same idea as the Clopper-Pearson interval for a proportion.
At the two extreme tables there is no finite estimate on one side. If the observed count is the largest possible, the conditional estimate has no finite value and the interval has no upper limit; if it is the smallest possible, the estimate is 0. The tool says plainly that such a table is too lopsided for a ratio rather than inventing a number.
Exact arithmetic keeps this honest at larger sizes. The BigInt type holds integers too large for ordinary numbers, so counts up to 5,000 per cell are handled without rounding, which means at most 10,001 tables. The heavy part runs in a worker so the page stays responsive. As a check, the results were compared with Python’s exact integers and with SciPy on 321 tables, with p-values agreeing to within about 2e-16.
The method has limits. It handles one 2 by 2 table, not larger tables, stratified tables or a Barnard-style test in which one margin is free. It treats the totals as fixed. It cannot tell you why two rows differ, and a small p-value does not measure how large or how important the difference is. For that, read the odds ratio and its interval, and look at the counts themselves.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Fisher's exact test Wikipedia
- Lady tasting tea Wikipedia
- Hypergeometric distribution Wikipedia
- Fisher's noncentral hypergeometric distribution Wikipedia
- Odds ratio Wikipedia
- Binomial proportion confidence interval Wikipedia
- Pearson's chi-squared test Wikipedia
- fisher_exact SciPy v1.18.0 Manual
- odds_ratio SciPy v1.18.0 Manual
- Fisher's Exact Test for Count Data R Documentation, stats package (R-devel manual)
- 7.4.6. Do all the processes have the same proportion of defectives? NIST/SEMATECH e-Handbook of Statistical Methods
- BigInt MDN Web Docs
- Web Workers API MDN Web Docs