Odds ratio calculator for a 2×2 table, with 95% CI

This odds ratio calculator with confidence interval takes a 2×2 table: the odds ratio is the odds of the event in one group divided by the odds in the other, ad ÷ bc, and its 95% CI is built on the log scale. It also gives the risk ratio (relative risk), the risk difference and the number needed to treat, each with a 95% CI.

Updated

Runs in your browser. Nothing you enter is uploaded, stored or sent anywhere.

How the odds ratio, risk ratio and NNT are calculated from a 2×2 table

With a and b the events and non-events in the experimental group, c and d the same in the comparator group, n₁ = a + b and n₂ = c + d, the measures and their standard errors are those of the Cochrane Handbook, Box 6.4.a, and of RevMan (Deeks and Higgins).

Effect measures from a 2×2 table, with 95% confidence intervals.

  • Odds ratio

    Estimate
    OR = ad ÷ bc
    95% confidence interval
    exp(ln OR ± 1.96 × √(1/a + 1/b + 1/c + 1/d))
  • Risk ratio

    Estimate
    RR = (a/n₁) ÷ (c/n₂)
    95% confidence interval
    exp(ln RR ± 1.96 × √(1/a + 1/c − 1/n₁ − 1/n₂))
  • Risk difference

    Estimate
    RD = a/n₁ − c/n₂
    95% confidence interval
    RD ± 1.96 × √(ab/n₁³ + cd/n₂³)
  • Number needed to treat

    Estimate
    NNT = 1 ÷ |RD|
    95% confidence interval
    The reciprocals of the RD’s limits

The ratios’ intervals are worked out on the log scale and exponentiated, so they aren’t symmetric around the estimate. The RD’s is a Wald interval on its own scale. Each P value is from the same z, the estimate divided by its SE.

The NNT, and an interval that crosses zero

The NNT is labelled NNTB when the experimental intervention means fewer bad outcomes (or more good ones), and NNTH when it means more: the Cochrane Handbook’s terms (15.4.2), which it prefers to “number needed to harm”. It’s rounded up to a whole number, as Cochrane does (15.4.4.1).

Its interval is the reciprocals of the RD’s limits (Altman 1998). When the RD’s interval includes zero, the NNT’s passes through infinity, so it’s written in one piece: NNTB 10 (NNTH 20 to ∞ to NNTB 4). Leaving out the interval, or printing “−20 to 4”, is the mistake Altman set out to fix.

Zero cells

If any cell is zero, 0.5 is added to all four before the odds ratio and risk ratio are computed, and the result says so. That’s the fixed correction the Cochrane Handbook describes (6.4.1.2 and 10.4.4.1), the default in metafor, and what OtterSR does. RevMan adds it only when a zero stops the calculation, so with a zero in a no-event cell its risk ratio can differ slightly. With no events in either group, or events in everyone, the OR and RR aren’t estimable and the calculator says so. The risk difference always uses the counts as entered.

Worked example: a 2×2 table

The calculator opens on Borenstein and colleagues’ example in chapter 5: 5 of 100 people had the event with the treatment and 10 of 100 with the control.

Borenstein and colleagues’ 2×2 table.
EventsNo eventsTotal
Treatment595100
Control1090100

Example: Working it through

The risks are 5 ÷ 100 = 0.05 and 10 ÷ 100 = 0.10, so the RR is 0.50. ln RR = −0.693 with an SE of 0.529, which gives a 95% CI of 0.18 to 1.41 (P = 0.19).

The OR is (5 × 90) ÷ (95 × 10) = 0.47. ln OR = −0.747 with an SE of 0.567, so the 95% CI is 0.16 to 1.44 (P = 0.19).

The RD is −0.050 with an SE of 0.037, so the 95% CI is −0.123 to 0.023 (P = 0.18).

The NNT is 1 ÷ 0.05 = 20, a benefit if the event is bad. The RD’s interval crosses zero, so the NNT’s is NNTH 44.1 to ∞ to NNTB 8.2.

These match the book’s results as reproduced with metafor, and the tests for this page also check Altman’s three NNT examples.

When to be careful

  • An odds ratio isn’t a risk ratio. When events are common, the OR is further from 1 than the RR, and reading it as a risk ratio overstates the effect (Cochrane 6.4.1.3). To re-express an OR as a risk, use the odds ratio to risk ratio calculator.
  • Which outcome is the event. The RR of death isn’t the reciprocal of the RR of survival, and the two can give different conclusions. Decide which you’ll use before you look (6.4.1.5).
  • The 0.5 correction. It avoids dividing by zero but pulls the estimate towards no difference and inflates its variance, and when the groups are unequal in size it biases the estimate in one direction (Cochrane 10.4.4.1). For a meta-analysis of rare events, see the methods in section 10.4.4.3.
  • Large-sample intervals. These are Wald intervals. With few events, or risks near 0 or 1, they can be poor.
  • An NNT needs its context. It depends on the comparator’s risk and the length of follow-up, so give both. Don’t compute one from totals added across trials; use the pooled result of a meta-analysis (15.4.4).

What to report

What to report: Report the table and the measure you chose

Give the events and totals in each group, then the effect measure with its 95% CI. Say if 0.5 was added for a zero cell.

Write an NNT as NNTB or NNTH with its follow-up time, and its interval in Altman’s form when the RD’s crosses zero.

In OtterSR, the Write stage computes these measures from the event counts you’ve extracted when it runs a meta-analysis, adding 0.5 to any table with a zero cell. It can also pool them by Mantel-Haenszel, or by Peto’s method for odds ratios, which work from the raw counts. See how OtterSR works.

Frequently asked questions

Odds ratio or relative risk?

For a meta-analysis, the Cochrane Handbook generally recommends either the risk ratio or the odds ratio over the risk difference (10.4.3). The RR is easier to read; the OR has better mathematical properties but is often misread as an RR. Many reviews analyse one and re-express the result as risks per 1000.

How do I calculate an odds ratio from a 2x2 table?

Multiply the events in the first group by the non-events in the second, and divide by the non-events in the first times the events in the second: ad ÷ bc. For the 95% CI, add 1/a + 1/b + 1/c + 1/d, take the square root, and go 1.96 of those either side of ln OR before exponentiating.

Is this a number needed to harm calculator too?

Yes. If the intervention increases the bad outcome, the calculator gives an NNTH: the number treated for one extra person to be harmed. Cochrane prefers NNTH to “number needed to harm”, which is easily misread (15.4.2).

Why does the NNT’s confidence interval go through infinity?

Because an RD of zero is an NNT of infinity. When the RD’s interval includes zero, it includes a benefit at one end and a harm at the other, and the NNT’s interval runs from one through infinity to the other (Altman 1998).

How to cite this tool

OtterSR. Odds ratio calculator for a 2×2 table, with 95% CI. https://www.ottersr.com/tools/odds-ratio-risk-ratio-calculator (accessed today’s date).

Please cite the method as well:

  • Altman DG. Confidence intervals for the number needed to treat. BMJ 1998;317(7168):1309–12.

  • Higgins JP, Li T, Deeks JJ (editors). Chapter 6: Choosing effect measures and computing estimates of effect [last updated August 2023]. In: Higgins JP, Thomas J, Chandler J, et al (editors). Cochrane Handbook for Systematic Reviews of Interventions version 6.5. Cochrane, 2024.

Sources

  1. Higgins JP, Li T, Deeks JJ (editors). Chapter 6: Choosing effect measures and computing estimates of effect [last updated August 2023]. In: Higgins JP, Thomas J, Chandler J, et al (editors). Cochrane Handbook for Systematic Reviews of Interventions version 6.5. Cochrane, 2024. https://www.cochrane.org/authors/handbooks-and-manuals/handbook/current/chapter-06
  2. Deeks JJ, Higgins JPT, Altman DG, McKenzie JE, Veroniki AA, Simmonds M (editors). Chapter 10: Analysing data and undertaking meta-analyses [last updated November 2026]. In: Higgins JPT, Thomas J, Chandler J, et al (editors). Cochrane Handbook for Systematic Reviews of Interventions version 6.5.1. Cochrane, 2026. https://www.cochrane.org/authors/handbooks-and-manuals/handbook/current/chapter-10
  3. Schünemann HJ, Vist GE, Higgins JP, et al. Chapter 15: Interpreting results and drawing conclusions [last updated August 2023]. In: Higgins JP, Thomas J, Chandler J, et al (editors). Cochrane Handbook for Systematic Reviews of Interventions version 6.5. Cochrane, 2024. https://www.cochrane.org/authors/handbooks-and-manuals/handbook/current/chapter-15
  4. Deeks JJ, Higgins JPT, on behalf of the Statistical Methods Group of The Cochrane Collaboration. Statistical algorithms in Review Manager 5. August 2010. https://www.cochrane.org/authors/handbooks-and-manuals/handbook/current/statistical-methods-revman5
  5. Altman DG. Confidence intervals for the number needed to treat. BMJ 1998;317(7168):1309–12. https://doi.org/10.1136/bmj.317.7168.1309
  6. Viechtbauer W. escalc: calculate effect sizes and outcome measures. Reference manual of the metafor package for R. https://wviechtb.github.io/metafor/reference/escalc.html
  7. Borenstein M, Hedges LV, Higgins JPT, Rothstein HR. Introduction to Meta-Analysis. Chichester: John Wiley & Sons, 2009. Chapters 4, 5 and 14. https://doi.org/10.1002/9780470743386
  8. Viechtbauer W. Borenstein et al. (2009): the book’s worked examples reproduced with the metafor package for R. https://wviechtb.github.io/meta_analysis_books/borenstein2009.html