Fisher's Exact Test Calculator
Hypothesis tests
- With margins fixed at 4 and 4 of 8, the observed table has hypergeometric probability 0.2286.
- Enumerate every table with these margins, from a = 0 to a = 4, and sum the probabilities no larger than 0.2286.
- Fisher exact two-sided p-value: 0.4857.
- The one-sided p-value is 0.2429 and the sample odds ratio is 9.00.
When a 2x2 table's counts are small, the chi-square approximation wobbles - and Fisher's exact test replaces the approximation with arithmetic. Fixing the margins, every table that could have occurred has a hypergeometric probability, and the p-value is an exact sum over the tables at least as improbable as yours. No expected-count rules, no continuity corrections, no asymptotics.
Enter the four counts a, b, c, d. The calculator returns the two-sided p-value (summing every table whose probability is at most the observed table's), the one-sided p-value (greater), the sample odds ratio, and the probability of the observed table itself. The chi-square page on this site covers the large-sample sibling; this page is for when the samples are not large.
Worked examples
Tea table 3/1/1/3, p 0.4857
(3 · 1 · 1 · 3)
| Two-sided p-value | 0.4857 |
| One-sided p (greater) | 0.2429 |
| Odds ratio | 9.00 |
| Probability of the observed table | 0.2286 |
Table 8/2/1/9, p 0.0055
(8 · 2 · 1 · 9)
| Two-sided p-value | 0.0055 |
| One-sided p (greater) | 0.0027 |
| Odds ratio | 36.00 |
| Probability of the observed table | 0.0027 |
Balanced 5/5/5/5, p 1.0000
(5 · 5 · 5 · 5)
| Two-sided p-value | 1.0000 |
| One-sided p (greater) | 0.6719 |
| Odds ratio | 1.00 |
| Probability of the observed table | 0.3437 |
Exact means exact
Condition on the margins and the count in one cell determines the whole table. Its distribution under independence is hypergeometric: the probability of each possible split is a ratio of binomial coefficients, computable to the last digit. Fisher's two-sided p-value sums the probabilities of the observed split and all splits no more probable than it.
The lady-tasting-tea table (3, 1 / 1, 3) is the founding example: margins of 4 and 4 over 8 cups, the observed table's probability 0.2286, and the two-sided sum 0.4857. Fisher's point stands: with eight cups, even a near-perfect performance cannot reach conventional significance - the design, not the taster, is underpowered.
That honesty is the test's virtue. It never promises more resolution than the counts contain.
- Conditions on both margins; cell counts follow the hypergeometric law
- Two-sided p sums all tables with probability at most the observed
- No minimum expected count required
- Outputs: two-sided p, one-sided p (greater), odds ratio, observed-table probability
Worked examples: three 2x2 tables
The tea table: 3/1/1/3, observed-table probability 0.2286, one-sided p 0.2429, two-sided p 0.4857, odds ratio 9.00. A large odds ratio wrapped in weak evidence - effect size and evidence are different things, and this little table teaches the difference better than any textbook paragraph.
A decisive table: 8, 2 / 1, 9. The observed table's probability is just 0.0027, the one-sided p is 0.0027, the two-sided p is 0.0055, and the odds ratio is 36.00. With margins of 10 and 9 over 20 observations, a split this lopsided is exactly what the exact test exists to certify.
A null table: 5, 5 / 5, 5. The observed table is the most probable configuration under independence (probability 0.3437), the odds ratio is exactly 1.00, the one-sided p is 0.6719, and the two-sided p is exactly 1.0000 - every table is 'as extreme', so the sum is everything.
Two-sided, defined carefully
The one-sided p-value (greater) is an unambiguous sum over one tail: for the tea table, the tables with a of 3 or 4 give 0.2429. The two-sided value is where definitions diverge - doubling the smaller tail is one convention; Fisher's own, summing tables with probability no greater than the observed table's, is the one used here and by R's fisher.test.
The probability-ordering definition respects the discreteness: in the decisive example the two-sided 0.0055 is a sum over both tails' qualifying tables, each judged by its own probability, not a doubled one-sided figure - though at these margins the two happen to sit close.
Whichever convention a report uses, it should name it. With small counts the conventions can straddle a significance threshold, and a p-value without its definition is an invitation to dispute.
The odds ratio
The sample odds ratio, ad/bc, summarises the table's tilt: 9.00 for the tea table, 36.00 for the decisive split, 1.00 for the null. It is the effect size that travels with the test - the p-value grades the evidence, the odds ratio states the size of the association the evidence concerns.
Read the pair together and the examples separate cleanly: 9.00 with p 0.4857 is a big claim on thin evidence (eight observations cannot carry it), while 36.00 with p 0.0055 is a big claim on adequate evidence. A report that gives only one of the two numbers hides which situation you are in.
Zero cells push the odds ratio to zero or infinity while the exact p-value remains perfectly computable - one more reason the test, not the ratio, is the primary output at small counts.
Fisher versus chi-square
The chi-square test approximates the same question and is excellent when expected counts are healthy - the usual rule asks for all expected counts at least 5, a condition the tea table (expected 2 per cell) fails outright. With margins of 4 and 4 the chi-square approximation is unreliable; enumeration over a from 0 to 4 is trivial and exact. That is the whole argument.
The cost of exactness is conservatism: because the discrete distribution has few attainable p-values, the test's true size sits below its nominal level, spending power. Mid-p adjustments recover some of it and are a reasonable refinement, but the classical exact test remains the reference standard small tables are judged against.
For large tables the two agree to reporting precision, and chi-square's speed and extensibility (bigger tables, trend tests) win. Choosing Fisher for a 2x2 with any small cell is not pedantry; it is using the tool whose assumptions the data actually meet.
The lady tasting tea
The test was born in a tea room: Muriel Bristol claimed she could tell whether milk or tea entered the cup first, and Fisher designed the experiment on the spot - eight cups, four of each kind, presented in random order, with the taster told the composition in advance. Her near-perfect performance is the 3/1/1/3 table of the first example, and Fisher's analysis of it in The Design of Experiments became the founding parable of exact inference.
The parable's moral is usually misread as being about tea. It is about design: Fisher showed that randomisation itself creates the probability distribution the test uses - the hypergeometric counts arise from the physical act of shuffling the cups, not from any assumption about populations. That is why the test needs no distributional assumptions: its probabilities are manufactured by the experimenter.
Modern exact tests for larger tables and stratified designs descend from this cup-counting, and the principle survives intact: when the design generates the distribution, inference can be exact.
Designing for exact tests
The tea table's lesson generalises: with tiny samples the attainable p-values form a coarse ladder - for margins of 4 and 4 the ladder has five rungs (a from 0 to 4) and its bottom sits above 0.05 no matter the outcome. A power calculation for an exact test enumerates that ladder in advance; if no possible table can reach significance, the experiment as designed cannot succeed and needs more subjects, not more hope.
Balanced margins maximise resolution: the decisive example's margins over 20 observations offer ten attainable tables, and its 0.0055 shows the ladder reaching well below 0.05. When the design allows it, balance is free power under exact testing.
Finally, fix the test and its sidedness before seeing the data. The one-sided 0.0027 and two-sided 0.0055 in the decisive example agree here; in borderline tables they will not, and choosing between them after the fact is the oldest form of p-hacking. Exact arithmetic deserves better company.
Barnard, Boschloo and the conservatism debate
Fisher's conditioning on both margins is a choice, not a law: in many experiments only one margin is fixed by design (the group sizes), while the success total is an outcome. Barnard's test and Boschloo's test exploit that freedom and are more powerful for the comparative-trial design, at real computational cost. Their existence reframes Fisher's test as the conservative reference, not the unique exact answer.
The conservatism has a concrete size: because attainable p-values are discrete - five rungs for the tea table's margins - a nominal 5 % Fisher test may operate well below that level for awkward margins, spending power the design paid for. Mid-p variants split the observed table's probability and recover much of the loss while keeping the exact machinery.
Practice remains Fisher-first for good reasons - universality, software agreement (R's definition is the one used here), and regulatory familiarity - but a report on a designed trial can fairly note the alternatives when a borderline Fisher result carries consequences.
Worked check: summing the tea table by hand
The margins 4, 4, 4, 4 over n = 8 admit five tables, with a running 0 to 4. Their hypergeometric probabilities are 0.0143, 0.2286, 0.5143, 0.2286, 0.0143 - symmetric, summing to 1. The observed a = 3 has probability 0.2286; the two-sided rule collects every table at or below that probability: 0.0143 + 0.2286 + 0.2286 + 0.0143 = 0.4857, the value this page reports.
The one-sided (greater) tail collects a of 3 and 4: 0.2286 + 0.0143 = 0.2429. Five numbers, checkable on an envelope, exercise every definition on the page - which is precisely why this 90-year-old example still opens the textbooks.
Scale the same design up and the ladder of attainable p-values grows fine enough for the test to bite - the decisive example's 0.0055 over 20 observations is the same machinery with more rungs. The tea table's coarseness is a property of eight, not of the method.
FAQs
What is the two-sided p for the tea table (3, 1, 1, 3)?
0.4857.
What does the table (8, 2, 1, 9) give?
0.0055, with odds ratio 36.00.
And the balanced table (5, 5, 5, 5)?
1.0000.
What is the one-sided p for the tea table?
0.2429.
What is the probability of the observed tea table itself?
0.2286.
Why exact?
With margins of 4 and 4 the chi-square approximation is unreliable; enumeration covers a from 0 to 4.