Relative Risk and Odds Ratio Calculator (2×2 Table): RR, OR, Risk Difference, NNT and Attributable Risk
Enter the four counts of a 2×2 table (exposed or not, outcome or not) and get every standard measure of association with confidence intervals: relative risk, odds ratio, risk difference, number needed to treat or harm, and attributable fractions. Pick your study design, and the tool shows only the measures that are valid for it. A second tab pools several strata with the Mantel–Haenszel method to adjust for a confounder.
| Total | |||
|---|---|---|---|
| Total |
Cells: a = exposed with outcome, b = exposed without, c = unexposed with outcome, d = unexposed without. For a trial, “exposed” is the treatment group and the outcome is the event (death, infection, cure…).
One row per stratum (for example age group or study centre), each with its own 2×2 counts. The Mantel–Haenszel estimate is the exposure effect adjusted for the stratifying variable.
| Stratum | a (exp., outcome) | b (exp., none) | c (unexp., outcome) | d (unexp., none) |
|---|
- PriceFree, no login or sign-up needed
- Your dataProcessed in your browser, never uploaded
- Works onPhone, tablet or computer, any modern browser
- Made byDr. Muhammad Aammar Tufail, Codanics
- Published17 November 2026
- Last updated16 November 2026
📚 How to cite this tool
This tool is free. If it helped your thesis, paper, report or assignment, please cite it. It keeps the tools free and helps other students find them.
Tufail, M. A. (2026). Relative risk and odds ratio calculator (2×2 table): RR, OR, risk difference, NNT and attributable risk [Online tool]. Codanics. Retrieved 16 November 2026, from https://codanics.com/tools/relative-risk-odds-ratio-calculator/
In-text citation: (Tufail, 2026) · Narrative: Tufail (2026)
The access date is today’s date, filled in automatically. Author: Muhammad Aammar Tufail. Published 17 November 2026.
How to use the relative risk and odds ratio calculator
- Choose your study design. Cohort studies and randomised trials give risks, so you get the relative risk, risk difference and NNT. Case-control studies sample on the outcome, so only the odds ratio is valid. Cross-sectional studies give prevalence ratios.
- Type the four counts: a exposed with the outcome, b exposed without it, c unexposed with the outcome and d unexposed without it. Rename the row and column labels if you like. Or paste raw data (one row per person, two yes/no columns) with Paste from Excel or Upload CSV / Excel.
- Read the measures of association and their confidence intervals. If the interval for RR or OR excludes 1, the association is statistically significant.
- To adjust for a confounder such as age or sex, open the Stratified (Mantel–Haenszel) tab and enter one 2×2 table per stratum. Compare the crude and adjusted estimates.
- Copy the table into Word, download it as CSV, or copy the ready-made results sentence.
Relative risk or odds ratio: which one should you report?
The relative risk (RR), also called the risk ratio, compares the probability of the outcome in exposed and unexposed people. An RR of 2 means the exposed are twice as likely to develop the outcome. It needs risks, so it is only valid when you followed groups forward in time: cohort studies and randomised trials. The odds ratio (OR) compares odds instead of probabilities. It is the only valid measure in a case-control study, because there the investigator chose how many cases and controls to include, so the “risk” in the table is artificial. The OR is also what logistic regression reports.
When the outcome is rare (below about 10%), the OR and RR are almost equal. When it is common, the OR is further from 1 than the RR and should not be described as “times more likely”. In the example (30% vs 10%), RR = 3.0 but OR = 3.86.
Formulas
If any cell is zero, 0.5 is added to every cell before calculating the ratios (the Haldane–Anscombe correction). The chi-square test is Pearson’s (with Yates’ version shown too), and Fisher’s exact test is two-sided, as in R’s fisher.test().
Number needed to treat (NNT) and to harm (NNH)
NNT is the number of people who must receive the treatment for one extra person to benefit, compared with the control. If the risk of death falls from 10% to 6%, the risk difference is −4 percentage points and NNT = 1/0.04 = 25. When the risk difference is positive, the same quantity is the number needed to harm. If the confidence interval of the risk difference includes zero, the NNT interval passes through infinity, so it is reported as “NNH x to ∞ to NNT y”, following Altman (1998).
Adjusting for a confounder with Mantel–Haenszel
A confounder is linked to both the exposure and the outcome, such as age when studying smoking and heart disease. Splitting the data into strata of the confounder and pooling the stratum-specific estimates gives the Mantel–Haenszel OR or RR, which is adjusted for that variable:
A common rule of thumb is that a change of more than 10% between the crude and adjusted estimates indicates confounding. If the stratum-specific ORs differ a lot (a significant Woolf homogeneity test), the exposure effect genuinely depends on the stratum. That is effect modification, and you should report the strata separately. For more than one confounder at a time, use logistic regression.
epiR::epi.2by2() (Wald intervals); the Newcombe interval matches Newcombe’s method 10 coded in R; the tests match fisher.test() and chisq.test(); the Mantel–Haenszel OR, CI and test match mantelhaen.test() and the MH RR matches epi.2by2(). Confidence intervals for the attributable fractions are calculated here from the RR limits and by the delta method, so they can differ slightly from epiR, which uses other approximations.References: Altman DG (1998) BMJ 317:1309–1312 · Robins J, Breslow N, Greenland S (1986) Biometrics 42:311–323 · Greenland S, Robins JM (1985) Biometrics 41:55–68 · Newcombe RG (1998) Stat Med 17:873–890 · Rothman KJ, Greenland S, Lash TL (2008) Modern Epidemiology, 3rd ed.
Frequently asked questions
How do I calculate relative risk from a 2×2 table?
Divide the risk in the exposed group, a/(a+b), by the risk in the unexposed group, c/(c+d). For example, 30/100 ÷ 10/100 = 3.0. The calculator also gives the 95% confidence interval using the log method.
Can I calculate relative risk in a case-control study?
No. In a case-control study you choose how many cases and controls to include, so the risks in the table are not real risks. Report the odds ratio instead. If the disease is rare, the odds ratio approximates the relative risk.
Why is my odds ratio bigger than my relative risk?
When the outcome is common, odds grow faster than probabilities, so the odds ratio is always further from 1 than the relative risk. They are close only when the outcome affects less than about 10% of people.
What does a 95% confidence interval that includes 1 mean?
For ratio measures (RR, OR), a value of 1 means no difference. If the interval includes 1, the data are compatible with no association, which corresponds to p > 0.05.
How is the number needed to treat calculated?
NNT = 1 / absolute risk reduction. If a treatment lowers the risk from 20% to 15%, the absolute risk reduction is 0.05 and NNT = 20. Round NNT up to the next whole number when you report it.
What is the population attributable fraction?
It is the proportion of all cases in the population that would not occur if the exposure were removed, assuming the association is causal. It depends on both the strength of the association and how common the exposure is.
When should I use the Mantel–Haenszel method?
Use it when you want an estimate adjusted for one categorical confounder, such as age group, sex or study centre, or to pool 2×2 tables from several sites. For several confounders, use logistic or Poisson regression.
Do I need to log in or create an account to use the relative risk and odds ratio calculator?
No. There is no login, no sign-up and no email required. Open the page and start using it straight away, for free, on any device.
How do I cite this tool in my thesis or paper?
Use the citation box on this page. In APA 7th edition: Tufail, M. A. (2026). Relative risk and odds ratio calculator (2×2 table): RR, OR, risk difference, NNT and attributable risk [Online tool]. Codanics. Retrieved [date you used it], from https://codanics.com/tools/relative-risk-odds-ratio-calculator/. BibTeX, RIS (EndNote, Mendeley, Zotero), MLA, Harvard, Chicago and Vancouver formats are also available.
Free guides and courses from Codanics
More free tools
See all free Codanics tools → · Codanics on YouTube · WhatsApp channel