Effect sizes for a 2×2 table

Odds Ratio Calculator

Enter the four counts of a 2×2 table and this odds ratio calculator returns the odds ratio, relative risk, risk difference and number needed to treat — each with its confidence interval and the interval method named. Declare your study design and the measures your design cannot support are withheld, with the reason printed, instead of being silently computed.

Table 1. The odds ratio calculator. Type your four counts, rename the labels to match your study, and declare the study design — the results update as you type.

Your 2×2 table

Total
10
6
Total 9 7 16

A zero cell is allowed: the sample odds ratio is then honestly 0 or infinite, and any Haldane–Anscombe +0.5 corrected figure is shown only with its label visible — never silently.

Copy two rows of two counts from a spreadsheet (tab- or comma-separated) and paste — the first four numbers fill a, b, c, d in reading order.

Study design
Study design

The design decides which measures exist. A case-control study fixes the case:control ratio by sampling, so only the odds ratio can be estimated from it — relative risk, risk difference and NNT are withheld below, with the reason printed.

Presets:

Each preset is a real worked example used on this page — the drug trial is the default table, worked through every measure below.

Your results — OR, RR, risk difference and NNT

Sample odds ratio (ad/bc)

—

Sample odds ratioad/bc, straight from your counts — never corrected silently
—
Conditional-MLE odds ratiothe estimate R's fisher.test reports; a different estimator of the same quantity
—
Cornfield inversion of the exact test — the only interval on this page called exact
—
logit interval — an approximation, shown for comparison
—
Relative risk (risk ratio)
—
Risk differenceabsolute risk difference; CI by the Wald method
—
1 / |risk difference|, always rounded up to the next whole person
—
Fisher's exact p — companiontwo-sided, by probability ordering — the definition R and SciPy use; the same figure the homepage gives this table
—

Forest plot — OR and RR side by side

Points are the estimates; whiskers are the 95% intervals, on a log scale with 1 (no association) marked. The odds ratio is drawn with its Cornfield exact interval.

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

How to use the odds ratio calculator

  1. Enter the four counts

    Type your 2×2 table into the grid — row 1 is the exposed (or treated) group, row 2 the unexposed group; column 1 is the outcome, column 2 no outcome. Or paste two rows of two counts copied from a spreadsheet. Counts must be whole numbers; percentages cannot be used, because every measure here depends on how many observations stand behind each proportion.

  2. Rename the labels

    Replace Exposed / Unexposed and Outcome / No outcome with your own group and outcome names. The labels flow into the interpretation sentence in the result panel, so the sentence you copy names your groups, not generic ones.

  3. Declare the study design

    Pick cohort / trial, case-control or cross-sectional. This is not decoration: a case-control sample fixes the case:control ratio, so risks cannot be estimated from it, and the calculator withholds the relative risk, risk difference and NNT with the reason printed. Cohort, trial and cross-sectional data support all four measures.

  4. Read the measures, each with its interval

    The headline is the sample odds ratio (ad/bc) with its plain-language interpretation sentence. Below it sit the conditional-MLE odds ratio, the Cornfield exact confidence interval, the Woolf interval labelled as an approximation, and — when the design allows — the relative risk, risk difference and NNT or NNH, plus Fisher's exact two-sided p-value as a companion.

  5. Copy, share or print

    Copy the result block as plain text, share a link that encodes your table and design in the URL, or print a clean result sheet. Everything runs in your browser; nothing is uploaded.

What is an odds ratio?

The odds ratio compares the odds of an outcome in two groups. The odds of the outcome in the exposed group are the count with the outcome divided by the count without it (a/b); the odds in the unexposed group are c/d. The odds ratio is the ratio of those two odds, which is why it collapses to the cross-product of the 2x2 table: OR = ad/bc. An odds ratio of 1 means the odds are identical in the two groups — no association in this table. Above 1, the odds of the outcome are higher in the first group; below 1, they are lower.

Odds are not probabilities, and the language matters. If 8 of 10 treated patients improve, their risk of improvement is 0.80 but their odds are 8:2, or 4 to 1. Against 1 of 6 improving on control (risk 0.167, odds 1:5 = 0.2), the relative risk is 0.80 / 0.167 = 4.80 while the odds ratio is 4 / 0.2 = 20. Both describe the same table; they answer different questions. That is why the interpretation sentence on this page always says “the odds of the outcome are X times higher” — never “X times more likely”, which is risk language and belongs to the relative risk.

The odds ratio earns its central place in epidemiology for one structural reason: it is the only one of these measures that survives case-control sampling. In a case-control study the investigator chooses how many cases and controls to sample, so the proportions with the outcome inside each exposure group are artefacts of that choice — but the odds ratio computed from the table is not distorted by it, because the sampling fractions cancel in the cross-product. Jerome Cornfield's 1951 justification of this point is what made the case-control design practical, and it is why the design selector above gates the other measures rather than the odds ratio.

The formulas — OR, RR, risk difference, NNT

All four measures come from the same four counts. Write the table as [[a, b], [c, d]] — exposed with and without the outcome, then unexposed with and without it — with row totals n₁ = a + b and n₂ = c + d.

Odds ratio (cross-product)

OR = ad / bc

The odds in row 1 (a/b) divided by the odds in row 2 (c/d). This is the sample odds ratio; R's fisher.test reports the conditional maximum-likelihood estimate instead, which is why the two numbers differ slightly on the same table.

Standard error of the log odds ratio

SE(ln OR) = √(1/a + 1/b + 1/c + 1/d)

Every cell contributes its reciprocal; small cells dominate the standard error, which is why one small count makes the interval wide.

Woolf (logit) confidence interval — an approximation

exp(ln OR ± z · SE(ln OR))

Woolf's 1955 interval works on the log scale, where the sampling distribution is closer to normal, then exponentiates back. It is labelled an approximation wherever this page prints it; the Cornfield interval is the exact one.

Relative risk (risk ratio)

RR = [a / (a+b)] / [c / (c+d)]

A ratio of risks (proportions), not odds. Its confidence interval uses the log method: SE(ln RR) = √(1/a − 1/(a+b) + 1/c − 1/(c+d)).

Risk difference (attributable risk)

RD = a / (a+b) − c / (c+d)

The absolute difference in risks, in probability units. Its interval here is the Wald interval: RD ± z · √(p₁(1−p₁)/n₁ + p₂(1−p₂)/n₂).

Number needed to treat

NNT = 1 / |RD|, rounded up

How many people must be treated (or exposed) for one extra outcome, on average. Always rounded up to the next whole person; when RD is negative the same figure is reported as the number needed to harm (NNH).

The cross-product: OR = ad/bc

Multiply the diagonal cells and divide: a × d over b × c. For the drug-trial table [[8, 2], [1, 5]] that is (8 × 5) / (2 × 1) = 40 / 2 = 20. The explorer below computes the cross-product live — change any count and watch ad, bc, the log odds ratio and its standard error move. Notice that swapping the two rows inverts the ratio (20 becomes 0.05), and swapping the columns does the same: the odds ratio is a statement about a direction, so the direction — which group is row 1, which column is the outcome — must be fixed before the number means anything.

Standard error of the log odds ratio

Odds ratios are skewed — they live on (0, ∞) with 1 in the middle on a multiplicative scale — so intervals are built on the log scale, where ln(OR) is roughly normal with standard error √(1/a + 1/b + 1/c + 1/d). For the drug-trial table that is √(0.125 + 0.5 + 1 + 0.2) = √1.825 ≈ 1.351, and the Woolf 95% interval is exp(ln 20 ± 1.96 × 1.351) = [1.416, 282.4]. The formula also explains the zero-cell problem at a glance: a single zero cell makes one reciprocal infinite, so the Woolf interval does not exist until something — a correction, or an exact method — replaces it.

a × d
—
b × c
—
OR = ad / bc
—
ln(OR)
—
SE(ln OR) = √(1/a + 1/b + 1/c + 1/d)
—
Woolf 95% interval (approximation)
—

Worked example — one table, every measure

Drug trial [[8, 2], [1, 5]] — a constructed teaching example

A small constructed trial table used throughout this site: 8 of 10 patients improved on treatment, 1 of 6 improved on control. Design: cohort / trial, so all four measures are valid. Enter these counts above to reproduce every figure.

  1. Cross-product: OR = ad/bc = (8 × 5) / (2 × 1) = 40 / 2 = 20.00 — the sample odds ratio.
  2. Conditional-MLE odds ratio: 15.47 — the estimate R's fisher.test reports for the same table. Two estimators, one quantity; both are printed, labelled.
  3. Cornfield exact 95% CI: [1.009, 1059.6] — exact, and honestly wide: N = 16 barely excludes an odds ratio of 1.
  4. Woolf 95% interval: [1.416, 282.4] — the logit approximation; narrower than the exact interval, which is the usual direction of its error in small samples.
  5. Risks: 8/10 = 0.800 on treatment, 1/6 = 0.167 on control. Relative risk = 0.800 / 0.167 = 4.80 (log-method 95% CI [0.781, 29.50]).
  6. Risk difference = 0.800 − 0.167 = 0.6333 (Wald 95% CI [0.246, 1.021]).
  7. NNT = 1 / 0.6333 = 1.58, rounded up to 2: treat two patients for one extra improvement, on average.
  8. Companion significance: Fisher's exact two-sided p = 0.0350 by probability ordering — the same figure the homepage calculator gives this table.

OR 20.00 (exact 95% CI [1.009, 1059.6]), RR 4.80, RD 0.6333, NNT 2, Fisher two-sided p = 0.0350. Note how far apart OR and RR sit on the same table — the outcome here is common, which is exactly when the odds ratio exaggerates, as the OR-vs-RR section explains.

a × d
—
b × c
—
OR = ad / bc
—
ln(OR)
—
SE(ln OR) = √(1/a + 1/b + 1/c + 1/d)
—
Woolf 95% interval (approximation)
—

Which measure fits your study? — the study-design table

The same 2×2 table supports different measures depending on how the data were sampled. This is the table the design selector in the calculator enforces.

Which measures each study design can estimate from a 2×2 table.
Cohort study / randomised trialYesYesYesYes
Cross-sectional studyYesYes (a prevalence ratio)YesYes, with care
Case-control studyYes — the measure of this designNo — risks not estimableNo — risks not estimableNo — needs the risk difference

Case-control studies — odds ratio only

A case-control study samples on the outcome: the investigator fixes how many cases and how many controls to recruit, so the column totals are chosen, not observed. The proportion of exposed people who are cases inside such a sample says nothing about the risk of the outcome in the population — change the case:control ratio and every 'risk' in the table changes with it, while the odds ratio stays put. That is why this calculator, set to case-control, prints the reason and withholds the relative risk, risk difference and NNT rather than computing numbers the design cannot support. Under the rare-outcome rule (next section) the odds ratio from a case-control study still approximates the relative risk the investigators actually want.

Cohort studies and trials — all four measures

A cohort study or trial samples on exposure (or assigns it), then observes outcomes, so both row risks are genuine estimates and the full set — odds ratio, relative risk, risk difference and NNT — is available. Cross-sectional data behave the same way arithmetically, with the relative risk read as a prevalence ratio. Even when all four exist, report more than one: the odds ratio and relative risk carry the relative effect, the risk difference and NNT carry the absolute effect, and a large relative effect on a rare outcome can be a trivial absolute one. CONSORT-style trial reporting expects the absolute numbers alongside the relative ones for exactly this reason.

Odds ratio vs relative risk

The relative risk (risk ratio) divides one risk by another: [a/(a+b)] / [c/(c+d)]. The odds ratio divides one odds by another. They point the same way — both are 1 when there is no association, both above 1 together and below 1 together — but they are equal only when the outcome is rare, and they drift apart as the outcome becomes common, with the odds ratio always further from 1. On the worked example the gap is dramatic: RR 4.80 against OR 20.00, because improvement is a common outcome in that table (9 of 16 patients). Neither number is wrong; quoting the 20 where a reader expects a risk ratio is.

A relative risk calculator and an odds ratio calculator are therefore not interchangeable, and the choice is usually made by the design, not by preference: cohort and trial data give you both, case-control data give you the odds ratio alone. If you are reading a paper, check which measure is printed before comparing numbers across studies — a meta-analysis that mixes the two without conversion is comparing different quantities.

When the odds ratio approximates the relative risk — the rare-outcome rule

When the outcome is rare in both groups — risks under roughly 10% — odds and risks nearly coincide (a risk of 0.02 is odds of 0.0204), so the odds ratio approximates the relative risk closely. This rare-disease assumption is what lets a case-control odds ratio stand in for the relative risk the design cannot compute directly. 'Rare' is judged on the risks in your groups, not on how the study feels: at a risk of 0.40 versus 0.20 the relative risk is exactly 2 but the odds ratio is already 2.67.

When the outcome is common — why the OR exaggerates

Odds stretch as risks grow: a risk of 0.80 is odds of 4, a risk of 0.90 is odds of 9, and a risk of 0.99 is odds of 99. Dividing two stretched numbers inflates the ratio, so with a common outcome the odds ratio exaggerates — it sits further from 1 than the relative risk, in whichever direction the effect runs. The worked example is the extreme case: risks 0.800 and 0.167 give RR 4.80, while odds 4.0 and 0.2 give OR 20. If your outcome is common and your design allows risks, lead with the relative risk and risk difference, and let the odds ratio play its supporting role.

Interpreting the confidence interval

A confidence interval for the odds ratio is read against 1, the no-association value: an interval entirely above 1 is compatible only with higher odds in the first group; entirely below 1, only with lower odds; an interval containing 1 is compatible with no association (and, usually, with a range of effects on both sides — read the whole interval, not just whether it crosses). The width is information: the drug-trial exact interval [1.009, 1059.6] says the data rule out 'no association' only barely and are consistent with anything from a negligible effect to an enormous one. That is the honest statement a sample of 16 can make, and a narrow-looking interval from an approximation does not add information the data do not contain.

Report the interval with its method named and its level stated — “OR = 20.00 (95% CI [1.009, 1059.6], Cornfield exact)” is a complete report; “OR = 20 (CI 1.4–282)” silently swaps in the Woolf approximation. The same discipline applies to the other measures: the relative risk interval here is by the log method, the risk difference interval is the Wald interval, and the NNT interval is the inverted risk-difference interval — which, when the risk-difference interval spans 0, runs through infinity and is reported as two arms (NNT of at least X on the benefit side, NNH of at least Y on the harm side), because 'somewhere between a large benefit and a large harm, passing through no effect' cannot be written as one finite range.

Woolf (logit) interval vs the exact interval

The Woolf interval (Woolf, 1955) builds a normal interval for ln(OR) and exponentiates it. It is fast, standard, and adequate for large counts — and it is an approximation whose coverage can fall short in small samples, typically by being too narrow, as on the worked example ([1.416, 282.4] against the exact [1.009, 1059.6]). The Cornfield interval inverts the exact test itself: it collects every odds ratio the exact test would not reject at the stated level, so it is exact in the same sense the p-value is, and it behaves correctly with zero cells, where the Woolf interval does not exist. This page prints both, labelled, and calls only the Cornfield interval exact.

What if a cell is zero? — the Haldane–Anscombe correction, labelled

A zero cell breaks the sample odds ratio in an informative way: if b or c is 0 the cross-product divides by zero and the sample odds ratio is infinite; if a or d is 0 it is exactly 0. This calculator says so in words and leads with the conditional-MLE estimate and the Cornfield exact interval, both of which remain meaningful (the exact interval becomes one-sided, e.g. [1.339, ∞) for the perfect table [[4, 0], [0, 4]]). Nothing is quietly repaired.

The classical repair is the Haldane–Anscombe correction (Haldane, 1956; Anscombe, 1956): add 0.5 to every cell — a continuity correction — and compute the odds ratio and its Woolf interval from the corrected cells. For [[4, 0], [0, 4]] that gives (4.5 × 4.5) / (0.5 × 0.5) = 81, with Woolf interval [1.300, 5046.3]. Useful — but it is a different estimate, biased toward 1 by construction, and many calculators apply it silently so their 'odds ratio' never matches anyone else's. Here the corrected figure appears only under its label, stating that the +0.5 correction was applied and that it changes the estimate; the uncorrected sample figure always stands beside it. If you report a corrected figure, name the correction in your methods, exactly as you would name an interval method.

How to report it — interpretation sentences and APA

A complete report names the measure, the estimator, the interval and its method, the design, and the group counts. The interpretation sentence follows the locked pattern — odds language for an odds ratio: “The odds of improvement were higher in the treatment group than in the control group.” Never write that patients were “20 times more likely to improve” for an odds ratio of 20: 'likely' is probability language, and the relative risk that would justify it here is 4.80. Association language throughout — “was associated with”, not “caused” — unless the design is a randomised trial and even then the sentence reports the comparison, not a mechanism.

In APA style, an odds ratio is reported like other effect sizes, with the interval in brackets and the p-value without a leading zero: “Improvement was associated with treatment, OR = 15.47, 95% CI [1.01, 1059.64], p = .035 (Fisher's exact test, two-sided by probability ordering).” Note which odds ratio that sentence uses — the conditional-MLE estimate with the Cornfield exact interval, the pairing R's fisher.test reports; if you headline the sample odds ratio instead, say so and pair it with its interval. For cohort and trial data add the absolute measures: “RR = 4.80, 95% CI [0.78, 29.50]; risk difference = 0.63, NNT = 2.” Report the NNT rounded up, as a whole person, and flip to NNH when the difference runs the other way.

Odds ratio in Excel, R, Python and SPSS

In Excel the sample odds ratio is one formula — with the table in A1:B2, =(A1*B2)/(B1*A2) — and the Woolf interval is =EXP(LN(OR) ± 1.96*SQRT(1/A1+1/B1+1/A2+1/B2)) entered as two formulas. Excel has no built-in exact interval or odds-ratio function, so the Cornfield interval and conditional-MLE estimate need another route.

In R, fisher.test(matrix(c(8, 1, 2, 5), nrow = 2)) returns the conditional-MLE odds ratio (15.47 for the worked example) with the Cornfield exact interval; the epitools package's oddsratio() and riskratio() functions give the sample measures with their intervals, and epitab() lays out OR, RR and the risk difference for a table in one call. Mind the matrix fill order — R fills by column, which is why the call above lists 8, 1, 2, 5.

In Python, scipy.stats.fisher_exact([[8, 2], [1, 5]]) returns the sample odds ratio (20.0) and Fisher's two-sided p; statsmodels.stats.contingency_tables.Table2x2 gives the odds ratio, relative risk and risk difference with their confidence intervals from one object — the closest single route to this page's full set.

In SPSS, run Analyse → Descriptive Statistics → Crosstabs with the exposure in rows and the outcome in columns, tick Risk under Statistics: the 'Risk Estimate' table prints the odds ratio, the relative risks for both cohorts, each with its (Woolf-type) interval. As everywhere, check which estimator and interval a package prints before comparing its output with this page — the labels above each row of the result panel tell you exactly what to match.

Sources & method notes

Woolf, B. (1955). On estimating the relation between blood group and disease. Annals of Human Genetics, 19(4), 251–253 — the logit (Woolf) interval. Cornfield, J. (1956). A statistical problem arising from retrospective studies. Proceedings of the Third Berkeley Symposium, 4, 135–148 — the exact interval and the case-control justification of the odds ratio. Haldane, J. B. S. (1956) and Anscombe, F. J. (1956) — the +0.5 correction for zero cells. Fisher's exact p-values, the conditional-MLE odds ratio and the Cornfield interval are computed by the same engine as this site's homepage calculator, cross-checked against R's fisher.test and SciPy's fisher_exact; the relative risk interval uses the standard log method and the risk difference interval the Wald method, as labelled wherever they appear. The worked example is a constructed teaching example, presented as one — no real study stands behind its counts.

Frequently asked questions

What does an odds ratio of 2 mean?

It means the odds of the outcome in the first group are twice the odds in the second group. Odds are not probabilities: an odds ratio of 2 could be odds of 2:1 against 1:1 (risks 67% vs 50%, relative risk 1.33) or odds of 0.2:1 against 0.1:1 (risks about 17% vs 9%, relative risk about 1.83). The same odds ratio describes different absolute risks, which is why the risk difference and NNT belong beside it whenever the design allows them.

What is the difference between odds ratio and relative risk?

The relative risk divides one risk (proportion) by another; the odds ratio divides one odds by another. They agree in direction and coincide when the outcome is rare, but as the outcome becomes common the odds ratio moves further from 1 than the relative risk — on this page's worked example, RR is 4.80 while OR is 20.00 for the same table. Case-control studies can estimate only the odds ratio; cohort studies and trials can estimate both.

How do you interpret an odds ratio confidence interval?

Read it against 1, the no-association value. An interval entirely above 1 means the data are compatible only with higher odds in the first group; entirely below 1, only with lower odds; an interval containing 1 is compatible with no association — and with every value inside it, so quote the whole interval, not just the crossing. Name the method when you report it: the Cornfield interval is exact, the Woolf (logit) interval is an approximation and is usually narrower in small samples.

Can you calculate relative risk in a case-control study?

No. A case-control study fixes the case:control ratio by sampling — the investigator chooses how many cases and controls to recruit — so the proportions with the outcome inside the sample are artefacts of that choice, and risks, the relative risk, the risk difference and NNT cannot be estimated from the design. The odds ratio can, because the sampling fractions cancel in the cross-product; that is why this calculator withholds the risk-based measures, with the reason printed, when case-control is selected.

When is the odds ratio a good stand-in for the relative risk?

When the outcome is rare in both groups — risks under roughly 10% — odds and risks nearly coincide, so the odds ratio approximates the relative risk closely (the rare-disease assumption). At risks of 0.02 and 0.01 the two measures are 2.02 and 2.00; at risks of 0.40 and 0.20 they are already 2.67 and 2.00. Judge rarity from the risks in your groups, and if the outcome is common and your design allows it, report the relative risk itself.

Why is my odds ratio so much bigger than my relative risk?

Because odds stretch as risks grow: a risk of 0.80 is odds of 4, and a risk of 0.167 is odds of 0.2, so the ratio of odds (20) far exceeds the ratio of risks (4.80). The more common the outcome, the wider the gap, always with the odds ratio further from 1. It is arithmetic, not an error — but if your readers will read the number as a risk ratio, and your design supports risks, lead with the relative risk and risk difference instead.

What is NNT, and why is it rounded up?

The number needed to treat is 1 divided by the absolute risk difference: how many people must be treated, on average, for one extra outcome. For a risk difference of 0.6333 that is 1.58 — and it is always rounded up, to 2, because you cannot treat a fraction of a person and rounding down would overstate the benefit. When the difference runs the other way the same figure is the number needed to harm (NNH). Its confidence interval inverts the risk-difference interval and runs through infinity when that interval spans 0.

What do I do with a zero cell?

First, read the honest figures: a zero in b or c makes the sample odds ratio infinite, a zero in a or d makes it 0, and the conditional-MLE estimate and Cornfield exact interval still work (the interval becomes one-sided). If you need a finite cross-product figure, the Haldane–Anscombe correction adds 0.5 to every cell — for [[4, 0], [0, 4]] it gives 81 — but it changes the estimate and biases it toward 1, so report it only with its label attached, never as if it were the raw odds ratio.