Fisher's Exact Test Calculator - 2x2 P-Value and Odds Ratio

    Is 9 of 12 against 4 of 15 a real difference? Type the four counts of a 2x2 table and get the exact p-value, the odds ratio with its interval, the risk ratio and the smallest expected count.

    Parameters

    Enter data for calculations

    How many in group 1 had it

    The rest of group 1

    How many in group 2 had it

    The rest of group 2

    Two-sided unless the direction was fixed in advance

    Also sets the width of the odds ratio interval

    Optional, only labels the result

    Optional, only labels the result

    Optional column heading

    Form progress0 / 6 fields

    💡 Fill in all required fields to unlock the calculate button

    Fisher's exact test for a 2×2 table, with the odds ratio and its interval

    Two groups, one yes-or-no outcome, and counts too small to trust a chi-square approximation: that is the job this calculator does. Type the four cells of the table, choose a two-sided or one-sided hypothesis and a significance level, and it returns the exact p-value, the odds ratio with an exact confidence interval, the risk ratio and the difference in rates. For 9 of 12 in one group against 4 of 15 in the other, the two-sided p is 0.0213 and the odds ratio is 7.52, with a 95% interval from 1.14 to 68.03.

    It also shows the smallest expected count, which is the number that tells you whether you needed an exact test in the first place, and for small tables it lists every table that shares your row and column totals, so you can see exactly which ones went into the p-value.

    Problem: the chi-square test calls it significant, and the counts do not back it up

    Say 1 of 20 patients on a new protocol had a complication, against 6 of 20 on the old one. Run a Pearson chi-square without correction and you get χ² = 4.33 and p = 0.0375, below 0.05. Run Fisher's exact test on the same four numbers and p = 0.0915. Same data, opposite verdict. The chi-square p comes from a smooth curve that only fits well when every expected count is around 5 or more, and here the smallest one is 3.50.

    The gap is not rare. With 0 of 12 against 4 of 12, chi-square says p = 0.0285 and the exact test says 0.0932. With 7 of 8 against 2 of 10, chi-square gives 0.0044 and the exact test 0.0152, still significant but three times weaker. Yates' continuity correction pulls chi-square back toward the exact answer, and sometimes past it, which is why it is a patch rather than a fix.

    Which test fits your table

    The deciding facts are the design and the expected counts, not the total sample size on its own. The calculator prints the smallest expected count under the table, so you can read your row straight off this chart.

    Your situation Use Why
    Any expected count below 5 Fisher's exact test the chi-square curve misfits, the exact sum does not
    All expected counts 5 or more, two independent groups Either; chi-square is the usual default the two p-values land close together
    The same people measured twice (before and after) McNemar's test the rows are not independent groups
    More than two groups or outcomes Chi-square test of independence, or Fisher-Freeman-Halton this tool handles 2×2 only
    The outcome is a measurement, not yes or no t-test or a rank test such as Wilcoxon counting yes and no throws the numbers away

    What the calculator does instead of approximating

    It adds up real probabilities. Holding the row and column totals fixed, every possible table has a probability from the hypergeometric distribution. The two-sided p is the sum over all tables no more likely than yours. Nothing is estimated, so the answer is as valid at 8 observations as at 8,000.
    It reports the odds ratio the way statistics software does. The headline estimate is the conditional maximum likelihood odds ratio, the one R's fisher.test returns, with an exact interval found from the same distribution. The simple cross-product ad/bc sits in the table below it, because that is the one most textbooks print and the two differ at small counts (7.52 against 8.25 for the example above).
    It refuses input that would change the table. Percentages, decimals, negative numbers and thousands separators are rejected with a message, and so is a table with an empty row or column. A count typed as "1,000" is not quietly read as 1.

    The four cells and two choices, in order

    1. Group 1, with the outcome - how many in the first group had the event: clicked, passed, recovered, failed. Whole counts only, never a percentage.
    2. Group 1, without the outcome - the rest of that group. The two cells together must equal the group size.
    3. Group 2, with the outcome - the same count for the comparison group: control, placebo, version A. Zero is allowed.
    4. Group 2, without the outcome - the rest of the comparison group.
    5. Alternative hypothesis - two-sided unless you wrote down the expected direction before collecting data. When the data lean the predicted way, one-sided p is smaller than two-sided, often close to half of it, though not exactly (see the questions below).
    6. Significance level - 0.05 for most work, 0.01 when you run many comparisons or a false alarm is expensive, 0.10 for early exploratory looks. It also sets the width of the odds ratio interval.
    7. Names (optional) - labels for the two groups and the outcome. They only change the result table.
    8. Read the result - the p-value and verdict on top, then the odds ratio and its interval, the difference in rates and the smallest expected count.

    Seven tables run through the calculator

    Each row is a real input and the exact output, two-sided unless marked. Notice how often a double-digit gap in rates still misses 0.05 when the groups are small.

    Situation Group 1 Group 2 p Odds ratio (95% CI)
    Pass rate after a tutoring program 9 of 12 4 of 15 0.0213 7.52 (1.14 to 68.03)
    Lab mice responding to a compound 7 of 8 2 of 10 0.0152 21.40 (1.53 to 1,413)
    Complications, new protocol vs old 1 of 20 6 of 20 0.0915 0.13 (0.0025 to 1.25)
    Same, one-sided "fewer on the new protocol" 1 of 20 6 of 20 0.0457 only if the direction was set in advance
    Defects on two production lines, one with zero 0 of 12 4 of 12 0.0932 0 (0 to 1.34)
    Email A/B test on a small list, sign-ups 14 of 100 5 of 100 0.0513 3.08 (0.99 to 11.38)
    Fisher's tea-tasting table 3 of 4 1 of 4 0.4857 6.41 (0.21 to 626.24)

    The A/B row is worth a second look: 14% against 5% is almost three times the sign-up rate, and p still lands at 0.0513 with an interval that starts just under 1. The one-sided p for the same table is 0.0257, which is exactly why the direction has to be fixed before the test, not after the numbers come in.

    How small a group can still reach p below 0.05

    Take two equal groups and the most lopsided result possible: everyone in group 1 has the outcome, nobody in group 2 does. These are the smallest p-values each group size can ever produce. Below 4 per group, no result at all can reach 0.05 two-sided.

    Per group Best possible split Two-sided p One-sided p
    33 of 3 vs 0 of 30.10000.0500
    44 of 4 vs 0 of 40.02860.0143
    55 of 5 vs 0 of 50.00790.0040
    66 of 6 vs 0 of 60.00220.0011
    88 of 8 vs 0 of 80.0002below 0.0001

    Flip it around: with 10 per group and all 10 successes in group 1, group 2 can have at most 5 for the difference to count at 0.05. With 20 per group and 20 of 20 in group 1, group 2 can reach 15. A pilot of four or five per arm can only ever detect an all-or-nothing effect.

    What people ask before trusting the p-value

    When should I use Fisher's exact test instead of chi-square?
    When any expected count in the 2×2 table is below 5. The calculator prints the smallest expected count, so check that line. Above it, both tests agree closely and either is fine; below it, the chi-square p can be off by a factor of two or more, as the 0.0375 against 0.0915 example shows.
    Why is the odds ratio different from ad/bc?
    The headline figure is the conditional maximum likelihood estimate, found from the same distribution the p-value uses, and it is the estimate R's fisher.test prints. The cross-product ad/bc is the sample odds ratio. They converge as counts grow; at 9/3 against 4/11 they are 7.52 and 8.25. Both are shown.
    What does it mean when the interval runs to infinity or starts at zero?
    A zero in the table. If group 1 has 0 events, the best estimate of the odds ratio is 0 and only the upper bound is informative; with 0 of 12 against 4 of 12 it is 1.34, so the data cannot rule out equal odds. One-sided intervals are open on one end by construction.
    Is Fisher's test too conservative?
    It tends to be, because the p-value can only take a limited set of values when counts are small, so the real false-alarm rate sits below the nominal 0.05. That costs some power. In exchange, its false-alarm rate never goes above the level you chose, which is the trade most reviewers accept for small samples.
    Can I use it for a before and after comparison on the same people?
    No. Fisher's test assumes two independent groups. If the same 30 people answered yes or no twice, the pairs matter and McNemar's test is the right one, because it only looks at the people who changed their answer.
    Why is my one-sided p not exactly half of the two-sided one?
    Because the distribution of possible tables is not symmetric unless the margins are. The two-sided p adds every table no more likely than yours on both sides, and those tails rarely match. For 9/3 against 4/11 the one-sided p is 0.0165 and the two-sided 0.0213.
    How large can the counts be?
    Up to 100,000 per cell. The sum is still exact, but at that size every expected count is far above 5 and a chi-square test gives the same p, so the calculator says so under the result.

    Related tools

    Wilcoxon Test Calculator

    When the outcome is a measurement: signed-rank for pairs, Mann-Whitney U for two groups - See calculator

    Interquartile Range Calculator

    Quartiles, outlier fences and a box plot for any list of numbers - See calculator

    Probability Calculator

    Single, combined and conditional probabilities of events - See calculator

    Combinations & Permutations Calculator

    The counting behind every table probability the test adds up - See calculator

    Percentage Calculator

    Rates, percentage points and percent change between two groups - See calculator

    Standard Deviation Calculator

    Spread of a measured variable, when the outcome is a number rather than yes or no - See calculator

    Scientific Notation Calculator

    Reading very small p-values written as powers of ten - See calculator

    Similar calculators from this section