01
How to calculate an odds ratio
| Outcome: yes | Outcome: no | |
|---|---|---|
| Exposed / treated | a | b |
| Unexposed / control | c | d |
odds ratio = (a × d) ÷ (b × c)
relative risk = [a ÷ (a + b)] ÷ [c ÷ (c + d)]
risk difference = a ÷ (a + b) − c ÷ (c + d), NNT = 1 ÷ |risk difference|
02
Worked example
Of 100 exposed people 20 develop the outcome; of 100 unexposed people 10 do.
| Measure | Calculation | Result | 95% CI |
|---|---|---|---|
| Odds ratio | (20 × 90) ÷ (80 × 10) | 2.25 | 0.99 to 5.09 |
| Relative risk | 0.20 ÷ 0.10 | 2.00 | 0.99 to 4.05 |
| Risk difference | 0.20 − 0.10 | 10.0% | 0.2% to 19.8% |
| Number needed to harm | 1 ÷ 0.10 | 10 |
Both ratio intervals just include 1, so this difference falls short of significance at the 5% level even though the risk doubled.
03
Confidence intervals
SE(ln OR) = √(1/a + 1/b + 1/c + 1/d)
SE(ln RR) = √(1/a − 1/(a + b) + 1/c − 1/(c + d))
95% CI = exp( ln(ratio) ± 1.96 × SE )
The intervals are computed on the log scale, which is why they are not symmetric around the ratio. The p value comes from the same standard error: z = ln(ratio) ÷ SE, read against the normal distribution. In the example z = 1.95 and p = 0.052 for the odds ratio. An interval that excludes 1 means the association is statistically significant at the 5% level.
04
Odds ratio or relative risk?
- Cohort studies and trials follow groups forward, so risks are known: report the relative risk and the risk difference.
- Case-control studies fix the number of cases and controls, so risks cannot be estimated: only the odds ratio is valid.
- When the outcome is rare (under about 10%), the odds ratio is close to the relative risk. When it is common, the odds ratio is further from 1 than the relative risk: in the example, 2.25 against 2.00.
05
Zero cells and small counts
A zero in the table makes a ratio zero or infinite. The calculator then adds 0.5 to every cell (the Haldane–Anscombe correction) and says so. With counts that small the normal approximation behind the interval is weak; use the Fisher’s exact test calculator for the p value. For larger tables, see the chi-square calculator.
06
Common mistakes with odds ratios
- Reading an odds ratio as a relative risk when the outcome is common. With 50 of 100 exposed and 25 of 100 unexposed, the odds ratio is 3.0 but the risk only doubles (relative risk 2.0).
- A symmetric interval on the ratio scale. 2.25 ± 1.96 × SE of the ratio gives 0.41 to 4.09; the correct interval, computed on the log scale, is 0.99 to 5.09.
- Swapping the rows without saying so. Putting the unexposed group first gives 1 ÷ 2.25 = 0.444, the same association read the other way round.
- Ignoring a zero cell. With 0 of 100 exposed and 10 of 100 unexposed the raw odds ratio is 0; the calculator adds 0.5 to every cell and reports 0.043, and Fisher’s exact test should give the p value.
Trust
How this page is checked
- The calculation runs on code with automated tests against worked reference values. Every number in the examples on this page was produced by that same code, not typed by hand.
- The formulas and conventions used are stated on the page, so you can reproduce the result yourself or compare it with your own software.
- Last reviewed by the Sciloom team, Zebra Nine Studio Inc. It is a tool for research and teaching, not a substitute for a statistician, a validated lab method or medical advice.
Cite this page
Sciloom. (2026). Odds ratio calculator. Zebra Nine Studio Inc. https://sciloom.si/odds-ratio-calculator
Frequently asked questions
What does an odds ratio of 2 mean?
The odds of the outcome are twice as high in the exposed group as in the unexposed group. It does not mean the risk is doubled unless the outcome is rare.
What does it mean if the confidence interval includes 1?
A ratio of 1 means no association. If the 95% interval includes 1, the result is not statistically significant at the 5% level.
What is the difference between odds ratio and relative risk?
Relative risk compares probabilities (20% vs 10% is 2.0). The odds ratio compares odds (0.25 vs 0.111 is 2.25). They agree closely only for rare outcomes.
What is the number needed to treat?
One divided by the absolute risk difference: the number of people who must receive the treatment for one extra person to benefit (or, for a harmful exposure, to be harmed).