Fisher Exact Test Calculator

Enter four counts and get Fisher's exact p-value — two-sided by probability ordering, the way R computes it — with both odds ratios, the Cornfield exact confidence interval, expected counts and an APA-ready sentence. This Fisher exact test calculator enumerates every table with your margins, in your browser; nothing is uploaded.

Table 1. The 2 × 2 calculator. Type your counts; the row and column margins are held fixed, exactly as Fisher's test requires. Labels can be renamed.

Your 2×2 table

Total
10
6
Total 9 7 16

Zero cells: if a cell is zero, the sample odds ratio is 0 or infinite. This calculator says so in words; it never adds a silent 0.5 correction to make the number finite.

Four numbers in reading order fill a, b, c, d. Pasting a block into any cell fills the grid too.

Options — alternative, significance level, confidence level, mid-p

Alternative
Alternative

Two-sided is the standard choice; pick a side only if the direction was decided before seeing the data.

Also show the mid-p value (less conservative)
Worked examples:

The drug-trial table is a constructed teaching example, pre-filled so the result block has real figures to explain. The tea and NIST tables are the cited classics.

Result — Fisher's exact test

—

P(observed table)probability of exactly this table under the null
—
One-sided p (greater)tables with a top-left cell at least the observed
—
One-sided p (less)tables with a top-left cell at most the observed
—
Sample odds ratioad / bc — the odds ratio of this table itself
—
Conditional-MLE odds ratiothe estimate R's fisher.test reports
—
Cornfield's exact interval, attached to the conditional-MLE estimate
—
Woolf logit intervalan approximation — shown only for comparison
—

The same table through the approximations

Pearson chi-square p
—
Chi-square p, Yates correction
—
G-test p
—
Expected counts under independence
——
——

Report it (APA)

The OR is the conditional-MLE estimate and the interval is the exact (Cornfield) interval — the pairing R's fisher.test reports. A following note names the two-sided definition: probability ordering.

The same table in your software

R

Python (SciPy)

SPSS

Analyze → Descriptive Statistics → Crosstabs → Exact… → Exact (requires the Exact Tests module). The two-sided p SPSS prints uses the same probability-ordering definition.

Excel

Figure 1. Every table with these margins, and its probability under the null. Rows marked “counted” are the tables summed into the two-sided p-value — those no more probable than the one observed.
Top-left cell xTableP(x)Counted in two-sided p
Sum of all probabilities—

Your counts never leave your browser — the calculation runs on this page, and the share link encodes the table in the URL itself.

Your result explained

The headline number is the p-value for the alternative you selected — two-sided unless you changed it. Read it against your significance level: at the default α = 0.05, a p-value of 0.0350 is conventionally called statistically significant, meaning tables this uneven would arise under the null hypothesis of no association in about 3.5% of repeated experiments with the same margins. The panel separates what other calculators often merge: the probability of your exact table, both one-sided p-values, the sample odds ratio computed straight from your counts, the conditional maximum-likelihood estimate that R reports, and the Cornfield exact confidence interval. The expected counts and the Cochran line tell you whether a chi-square approximation would have been defensible for the same data.

What is Fisher's exact test?

Fisher's exact test answers a narrow question about a 2×2 table: if there were truly no association between the row variable and the column variable, how surprising is the table you observed — counting not just this table but every table with the same row and column totals that is at least as unlikely? It is called exact because the probability is computed by enumerating those tables directly, not by approximating a sampling distribution. R. A. Fisher introduced the test in the 1930s; it remains the reference method for categorical data with small counts and for any 2×2 table where an approximation cannot be trusted.

The lady tasting tea

The test's founding example is disarmingly small. Muriel Bristol, a colleague of Fisher's at Rothamsted, claimed she could tell whether milk had been poured into a cup before or after the tea. Fisher prepared eight cups — four milk-first, four tea-first — and Bristol identified all four of one kind correctly. Under the null hypothesis of guessing, the probability of a perfect classification is 1 in 70, about 0.0143 one-sided; the two-sided value for her table [[4, 0], [0, 4]] is 0.0286. Try it: the lady tasting tea preset above loads her table, and the calculator shows the infinite odds ratio a perfect score produces.

Why fixed margins give a hypergeometric null

Fix the margins and a 2×2 table has only one degree of freedom: choose the top-left cell and the other three are determined. Under the null hypothesis, that cell follows the hypergeometric distribution — the same distribution that governs drawing balls from an urn without replacement. If the column totals say 9 of 16 subjects improved, then under no association the number of improvers landing in a row of 10 is exactly the number of successes in 10 draws from an urn holding 9 improvers and 7 non-improvers. Fisher's test is nothing more — and nothing less — than adding up the right set of that distribution.

When to use it — the expected-count rule

Reach for Fisher's exact test when the counts are small enough that an approximation's error matters — the working rule, due to Cochran, is that the chi-square approximation becomes unreliable when expected counts fall below 5 in a substantial share of cells. The calculator prints the expected counts and the Cochran verdict for your table, so the choice is evidence-based rather than habitual. Try the checker with your own counts:

Expected counts under no association

————

The formula, with a worked example

With row totals R₁ and R₂, first-column total C₁, and grand total N, the probability of the table whose top-left cell equals x is the hypergeometric mass below. The worked example that follows it is computed live by the same engine as the calculator, so its figures can never drift from the tool's.

Hypergeometric probability of one table with fixed margins

P(x) = C(R₁, x) · C(R₂, C₁ − x) / C(N, C₁)

Equivalently, with the four cell counts a, b, c, d: P = (R₁! R₂! C₁! C₂!) / (a! b! c! d! N!). Your observed table contributes one such term; the p-values are sums of these terms over the tables the chosen alternative counts. The formula needs factorials of the margins only — no estimated parameters, no degrees of freedom, and no continuity correction, which is precisely why the result is exact rather than approximate.

Worked example. A second trial table — 8 improved of 10 on treatment, 1 of 10 on control — written [[8, 2], [1, 9]]. Its margins (rows 10 and 10, columns 9 and 11, N = 20) allow the top-left cell to range from 0 to 9.
x = 0 0.000060
x = 1 0.002679
x = 2 0.032151
x = 3 0.150036
x = 4 0.315075
x = 5 0.315075
x = 6 0.150036
x = 7 0.032151
x = 8 0.002679
x = 9 0.000060
x (top-left cell)TableP(x)Counted in two-sided p?
0 0 | 10
9 | 1
0.000060 Counted
1 1 | 9
8 | 2
0.002679 Counted
2 2 | 8
7 | 3
0.032151 —
3 3 | 7
6 | 4
0.150036 —
4 4 | 6
5 | 5
0.315075 —
5 5 | 5
4 | 6
0.315075 —
6 6 | 4
3 | 7
0.150036 —
7 7 | 3
2 | 8
0.032151 —
8 (observed) 8 | 2
1 | 9
0.002679 Counted
9 9 | 1
0 | 10
0.000060 Counted
Sum of all tables1.000000

The observed table's probability is 0.002679. One-sided (greater) adds x = 9, giving p = 0.002739. Two-sided probability ordering counts x = 0, 1, 8 and 9 — every table no more probable than the observed one — giving p = 0.005477. The sample odds ratio is 36 and the exact 95% CI is [2.058, 1766.9]. Load these counts in the calculator to reproduce every figure.

How the p-value is computed — every table with your margins

The calculator enumerates every table that shares your margins. For the default table there are seven: the top-left cell can range from 3 to 9, and each candidate table's probability comes from the formula above. The observed table (x = 8) has probability 0.023601. The one-sided p-value for 'greater' adds the probabilities of the observed table and every table more extreme in that direction (x = 9): 0.024476. The one-sided 'less' value adds everything down to x = 3: 0.999126 — large because the observed table sits near the top of the range.

The enumeration table

Figure 1 in the calculator lists all seven tables with their probabilities; the bars make the shape of the null distribution visible. The probabilities sum to exactly 1, which is the internal check that the enumeration is complete. Tables counted toward the two-sided p-value are marked — for the default table they are x = 3, 8 and 9, the tables whose probability does not exceed the observed table's 0.023601.

One-sided vs two-sided — and why two-sided is not double the one-sided

A one-sided test asks about one direction only: is the odds ratio greater than 1, or less than 1? A two-sided test asks whether the table is surprising in either direction, and Fisher's definition — the one R uses — counts every table whose probability is at most the observed table's probability. That is not the same as doubling the smaller one-sided value. Doubling would give 0.0490 for the default table; probability ordering gives 0.0350, because the hypergeometric distribution here is asymmetric — the far tail contributes one small table (x = 3, probability 0.010490) rather than a mirror image of the near tail. Choose the alternative before looking at the data; switching afterwards to whichever value is smaller is a quiet form of p-hacking.

Figure 2. Every table with the default margins (rows 10 and 6, columns 9 and 7, N = 16). The observed table is x = 8; the counted tables — x = 3, 8 and 9 — sum to the two-sided p-value 0.0350.
x = 3 0.010490
x = 4 0.110140
x = 5 0.330420
x = 6 0.367133
x = 7 0.157343
x = 8 0.023601
x = 9 0.000874
x (top-left cell)TableP(x)Counted in two-sided p?
3 3 | 7
6 | 0
0.010490 Counted
4 4 | 6
5 | 1
0.110140 —
5 5 | 5
4 | 2
0.330420 —
6 6 | 4
3 | 3
0.367133 —
7 7 | 3
2 | 4
0.157343 —
8 (observed) 8 | 2
1 | 5
0.023601 Counted
9 9 | 1
0 | 6
0.000874 Counted
Sum of all tables1.000000

Fisher vs chi-square

For the default table the approximations scatter around the exact answer: Pearson's chi-square gives p = 0.0134, the G-test 0.0107, and Yates' continuity-corrected chi-square 0.0510 — one of them even crosses the 0.05 line in the opposite direction from the others. The exact two-sided value is 0.0350. The approximations improve as counts grow and are perfectly serviceable for large tables, but they estimate a probability that Fisher's test computes outright. When expected counts are small, or when a result sits near a decision boundary, the exact figure is the one to report — with the approximation, if you show it at all, labelled as an approximation.

Four tests, one table: the default drug-trial table [[8, 2], [1, 5]] (N = 16).
TestStatisticTwo-sided p-valueStatus
Fisher's exact test—0.0350Exact
Pearson chi-squareχ² = 6.1120.0134Approximation
Chi-square with Yates correctionχ² = 3.8100.0510Approximation
G-test (likelihood ratio)G = 6.5150.0107Approximation

Pearson, Yates and G are approximations to a probability that Fisher's test computes exactly; the Yates figure (0.0510) even lands on the other side of 0.05.

The odds ratio — sample vs conditional MLE, and the exact CI

The p-value says how surprising the table is; the odds ratio says how strong the association is. The sample odds ratio is the cross-product of your counts, ad/bc — 20.00 for the default table, where the odds of improvement were 8:2 on treatment against 1:5 on control. R's fisher.test reports a different number, the conditional maximum-likelihood estimate (15.47 here): the odds ratio under which the observed table is the most likely outcome, given the margins. Neither is wrong; they estimate the same quantity by different routes, and this calculator shows both, labelled, rather than silently picking one. The Cornfield interval is the exact companion to the test: the set of odds ratios not rejected at your confidence level. Its width is the honest price of small samples — [1.009, 1059.6] barely excludes 1, which is exactly what p = 0.0350 says in another language.

Larger tables — the Freeman–Halton extension

The same enumeration extends to r×c tables — the Freeman–Halton extension — but the number of tables with given margins explodes combinatorially, and beyond modest sizes exact enumeration gives way to network algorithms or Monte Carlo simulation of the p-value. This calculator is deliberately a 2×2 instrument: it enumerates completely, instantly, and verifiably. For larger tables, run the same probability-ordering definition in R with fisher.test on an r×c matrix (adding simulate.p.value = TRUE when enumeration runs out of memory), and report that the value is simulated, with the number of replicates, when it is.

Why calculators disagree

Two calculators fed the same table can honestly print different p-values, because 'Fisher's exact test' names a family of conventions, not one number. The largest gap is the two-sided definition: probability ordering, as used by R and by this calculator, gives 0.0350 for the default table, while doubling the one-sided value gives 0.0490 — a difference that straddles many a significance threshold. Next, some tools quietly report the mid-p value, which halves the observed table's contribution and is systematically smaller. Others default to a one-sided alternative, or apply a continuity correction that belongs to the chi-square family, not to Fisher's test. The odds ratio causes a second, quieter disagreement: the sample cross-product (20.00) versus the conditional MLE (15.47). And intervals differ too — the Woolf logit interval is a normal approximation, while the Cornfield interval is exact. When a number matters, ask which conventions produced it; this page labels every one of its own.

Assumptions & when NOT to use it

  • Independent observations: each subject contributes to exactly one cell. Paired or repeated measurements need a paired test (McNemar), not Fisher's.
  • Categorical counts: the data are frequencies in a 2×2 classification — not means, percentages, or measurements.
  • Fixed margins by design or by conditioning: the test conditions on the observed row and column totals; it is valid whether or not the margins were fixed in advance, but the interpretation is conditional on them.
  • No minimum sample size: exactness does not require large counts — small samples cost power, not validity.

How to report it

Report the test, the alternative, the exact p-value, an effect size, and the interval — the APA sentence in the result panel is a complete template, and the routes below reproduce this calculator's two-sided p-value for the default table in R, Python, SPSS and Excel. Name the software and the two-sided convention in your methods section; 'Fisher's exact test, two-sided by probability ordering' is one unambiguous line.

R

fisher.test(matrix(c(8, 1, 2, 5), nrow = 2))

Python (SciPy)

from scipy.stats import fisher_exact
fisher_exact([[8, 2], [1, 5]])

SPSS

Analyse → Descriptive Statistics → Crosstabs: rows = treatment, columns = outcome; under Statistics tick Chi-square, and read the 'Fisher's Exact Test' row of the Chi-square Tests table — 'Exact Sig. (2-sided)'.

Excel

Excel has no Fisher function. The one-sided (greater) p-value for the default table is the sum of HYPGEOM.DIST(x, 10, 9, 16, FALSE) over x = 8 and 9 — or use the R or Python route above, which needs no manual summation.

Common mistakes

  • Doubling the one-sided p-value and calling it two-sided Fisher — the two-sided value is a sum over tables, not a multiple.
  • Reading the sample odds ratio and R's conditional estimate as a contradiction — they are two estimators of one quantity; report which one you used.
  • Calling the Woolf (logit) interval 'the exact CI' — it is a normal approximation; the Cornfield interval is the exact one.
  • Switching to a one-sided alternative after seeing the data — the direction must be fixed before the counts are known.
  • Reporting p = 0.035 as 'a 3.5% chance the null is true' — the p-value is the probability of tables this extreme given the null, not the probability of the null given the table.

Frequently asked questions

What is Fisher's exact test used for?

It tests whether two categorical variables are associated, using a 2×2 contingency table — typically whether an outcome rate differs between two groups. It is the standard choice when the counts are small, because it computes the exact probability of the table instead of relying on a large-sample approximation.

When should I use Fisher's exact test instead of chi-square?

Use Fisher's exact test when expected cell counts are small — Cochran's rule flags the chi-square approximation when expected counts below 5 appear in a substantial share of cells — or whenever an exact figure is required. For large tables with healthy expected counts, the chi-square test is accurate, extends to bigger tables, and is entirely appropriate.

How do I calculate Fisher's exact test by hand?

Fix the margins, then enumerate: the top-left cell can take only a handful of values, and each candidate table's probability is C(R₁, x)·C(R₂, C₁−x)/C(N, C₁). Add the probabilities of the tables your alternative counts — the observed table and beyond for one-sided, every table no more probable than the observed for two-sided. The worked example in the formula section carries out all ten tables of its example.

What is the difference between one-tailed and two-tailed Fisher's exact test?

A one-tailed (one-sided) test asks about a single direction: is the odds ratio greater than 1, or less than 1? A two-tailed (two-sided) test asks whether the table is surprising in either direction, counting every table whose probability is at most the observed table's. The two-sided value is not double the one-sided value, because the distribution of tables is usually asymmetric.

How do I interpret a Fisher's exact test p-value?

The p-value is the probability, computed under the null hypothesis of no association and conditional on the observed margins, of obtaining a table at least as extreme as yours. It is not the probability that the null hypothesis is true, and it says nothing by itself about the size or importance of the effect — that is the odds ratio's job.

Can Fisher's exact test be used for tables larger than 2×2?

Yes — the Freeman–Halton extension applies the same probability-ordering definition to r×c tables, and R's fisher.test implements it. The cost is combinatorial: the number of tables with given margins grows explosively, so large tables switch to network algorithms or Monte Carlo simulation. This calculator stays with 2×2, where enumeration is complete and instant.

Does Excel have a Fisher's exact test function?

No. Excel has no Fisher function, but its HYPGEOM.DIST function returns the probability of a single table, so a one-sided p-value can be built by summing it over the tables at least as extreme as yours. The reporting section below shows the exact formula for the default table; the R and Python routes there are less error-prone.

Why do two calculators give different two-sided p-values for Fisher's exact test?

Usually the two-sided convention: R sums probabilities by ordering (0.0350 for the default table), some packages double the one-sided value (0.0490), and SPSS prints both one- and two-sided exact significances with its own rounding. Odds ratios differ too — sample cross-product versus conditional MLE — and some tools report mid-p. Check which convention each number uses before concluding anyone is wrong.

Is Fisher's exact test one-sided or two-sided by default?

The test itself has no built-in default — software chooses. R's fisher.test defaults to two-sided, as does this calculator; some online tools quietly default to one-sided, which roughly halves the number. Two-sided is the safer default unless one direction was specified before the data were seen.

How do I report Fisher's exact test in APA style?

Report the exact p-value to three decimal places with no leading zero, the odds ratio, and its confidence interval: for example, 'Fisher's exact test (two-sided) showed a significant association between treatment and improvement, p = .035, OR = 15.47, 95% CI [1.01, 1059.64].' The result panel generates this sentence for your table and your chosen alternative.

What does an odds ratio of 2 mean?

It means the odds of the outcome in one row are twice the odds in the other row. Odds are not probabilities: an odds ratio of 2 could be odds of 2:1 against 1:1 (probabilities 67% vs 50%), or 0.2:1 against 0.1:1 (about 17% vs 9%). The same odds ratio can describe very different absolute risks.

What does 'exact' mean in Fisher's exact test?

It means the p-value is computed from the exact distribution of the table — the hypergeometric distribution over every table with your margins — rather than approximated by a chi-square distribution. Nothing about the calculation is estimated, so the result is valid at any sample size, however small the counts.

What if one of my cells is zero?

A zero in any single cell is handled exactly — the enumeration does not care — although the odds ratio may become infinite or zero, which the calculator reports honestly with a one-sided exact interval. What the test cannot survive is a zero margin: if an entire row or column is empty, there is only one possible table and no test exists.

Why is the confidence interval so wide?

Because small samples carry little information about the odds ratio, and the exact interval honestly reflects that. The default table (N = 16) gives [1.009, 1059.6]: the data rule out 'no association', barely, but are consistent with anything from a negligible effect to an enormous one. The interval narrows as the counts grow — width is information, reported rather than hidden.

Why is the odds ratio here different from the one R gives me?

Because there are two estimators. This calculator's headline sample odds ratio is the cross-product of your counts, ad/bc; R's fisher.test reports the conditional maximum-likelihood estimate instead — 20.00 versus 15.47 for the default table. Both estimate the same quantity by different routes, so this page shows both, labelled, rather than silently picking one.

Is the two-sided p-value just double the one-sided p-value?

No. Fisher's two-sided p-value is defined by probability ordering: it sums the probabilities of all tables whose probability is at most the observed table's. The hypergeometric distribution is usually asymmetric, so the far tail is not a mirror of the near tail — for the default table, doubling gives 0.0490 while probability ordering gives 0.0350.

Can I enter percentages instead of counts?

No — the test needs the actual counts. Percentages discard the sample size, and the sample size is exactly what determines how surprising a split is: 80% versus 20% means something entirely different at N = 10 and at N = 1,000. Convert percentages back to counts using your group sizes before entering them.

Is my data uploaded anywhere?

No. Every calculation runs in your browser, on your device; the counts you type are never sent anywhere. If you use the share button, the table is encoded in the link itself — nothing is stored on a server — so only share links you are happy for the recipient to read.

Sources & method notes

Fisher, R. A. (1935). The Design of Experiments. Edinburgh: Oliver & Boyd — the lady tasting tea appears in Chapter II. Salsburg, D. (2001). The Lady Tasting Tea. New York: W. H. Freeman. Cornfield, J. (1956). A statistical problem arising from retrospective studies. Proceedings of the Third Berkeley Symposium, 4, 135–148. Cochran, W. G. (1954). Some methods for strengthening the common χ² tests. Biometrics, 10(4), 417–451. NIST/SEMATECH e-Handbook of Statistical Methods, §7.3.5 (worked example 3). This calculator's engine was cross-checked against SciPy's fisher_exact and an independent exact enumeration.