Audited 31 Jul 2026·Last updated 28 Oct 2026·3 citations·Tier 3·0 uses

McNemar's Test Calculator

Run an exact McNemar test on paired yes/no data: enter the two discordant counts, b and c, and get the two-sided binomial p-value for a change.

McNemar's Test Calculator

Exact two-sided p value
0.0768
The exact two-sided p-value: the probability, if changes in either direction were equally likely, of a split between b and c at least as uneven as the one entered.
Model scope
Exact equal-discordance test for paired binary observations; it ignores concordant cells by design and does not establish pairing quality, independence between pairs, effect size, confidence interval, multiplicity, or causal interpretation.

Background.

Ask the same 100 people a yes-or-no question before and after something happens, a campaign, a treatment or a training course, and you cannot compare the two percentages with an ordinary two-sample test. The answers come in pairs from the same people, and most people give the same answer both times. The psychologist Quinn McNemar pointed out in 1947 that those unchanged pairs carry no information about whether the proportion shifted. Only the people who changed their answer do.

Lay the pairs out in a 2 × 2 table. Cell a holds pairs that were yes both times and d those that were no both times; b counts pairs that went from yes to no, and c those that went from no to yes. The change in the proportion answering yes is (c − b) divided by the number of pairs, so a and d drop out entirely. If nothing systematic happened, each person who switched was as likely to move one way as the other, and the split between b and c should look like heads and tails from b + c tosses of a fair coin.

This page applies that coin-toss logic directly, which is the exact form of McNemar's test. It finds the binomial probability of a split at least as lopsided as yours, in either direction, and reports it as a two-sided p-value. The better-known chi-square version, (b − c)² ÷ (b + c), approximates the same thing; it works well when there are many discordant pairs and poorly when there are few.

The same table fits other paired designs: two diagnostic tests read on the same patients, or cases matched one-to-one with controls. In each, a small p-value says the discordant pairs lean one way more than chance easily explains. It does not measure how large the effect is, check that the pairing was sound, or show what caused the shift.

What is mcnemar's test calculator?

McNemar's test asks whether a yes-or-no outcome is equally common under two paired conditions, using only the discordant pairs, those in which the two answers differ. Under the null hypothesis, the b pairs that changed one way and the c pairs that changed the other are a fair binomial split of their total. The exact version computes the two-sided probability of a split at least as uneven as the one observed, and that probability is the p-value. Equivalently, it is a sign test applied to the pairs that changed.

How to use this calculator.

  1. Build the 2 × 2 table of pairs first, so that each pair is counted once. Enter as b the pairs that were positive under the first condition and negative under the second, and as c the pairs that went the other way.
  2. Leave out the pairs that gave the same answer both times. There is no field for them because they do not affect the p-value.
  3. Both counts must be whole numbers, at least one must be above zero, and together they can total no more than 10,000.
  4. Read the exact two-sided p-value with the scope note beside it. Swapping b and c gives the same p-value, so the direction of change comes from which count is larger.

The formula.

p = 2 × P[Binomial(b+c, 0.5) ≤ min(b,c)], capped at 1

p = 2 × P[X ≤ min(b, c)], capped at 1, where X follows a binomial distribution with n = b + c trials and probability 0.5. Written out, P[X ≤ k] is the sum of C(n, i) ÷ 2ⁿ for i from 0 to k, where C(n, i) counts the ways of choosing i of the n discordant pairs. The 0.5 is the null hypothesis: a pair that changed was equally likely to change in either direction. Doubling the lower tail makes the test two-sided, counting splits just as lopsided in the opposite direction; because a binomial with probability 0.5 is symmetric, both tails are the same size. When b and c are equal or nearly so, doubling can take the sum past 1, and the answer is capped there. What drives the p-value is the imbalance between b and c relative to their total: a 4-to-12 split gives 0.0768, while the same 1-to-3 ratio with twice as many pairs, 8 to 24, gives 0.0070.

A worked example.

Example

A clinic asks 100 patients whether they exercise regularly, before and after a six-week coaching programme. Four who said yes before say no afterwards, so b = 4; twelve who said no before now say yes, so c = 12. The other 84 gave the same answer both times and play no part. There are b + c = 16 discordant pairs, and the smaller count is 4. If each switch were a fair coin toss, the chance of 4 or fewer of the 16 going one way is (1 + 16 + 120 + 560 + 1,820) ÷ 2¹⁶ = 2,517 ÷ 65,536 = 0.0384. Doubling it to cover a split just as uneven in the other direction gives an exact two-sided p-value of 0.0768. The chi-square shortcut, (12 − 4)² ÷ 16 = 4.0, would give p ≈ 0.0455 and fall below 0.05 where the exact test does not; with the continuity correction it gives about 0.0801. With only 16 discordant pairs, the exact figure is the more reliable one.

discordant B4
discordant C12

Frequently asked questions.

Why don't the people who gave the same answer both times count?
They add equally to the before and after proportions, so they cannot move the difference between them. With 100 pairs, the change in the yes proportion is (c − b) ÷ 100 whether 84 or 984 people stayed put. Concordant pairs do matter when you describe the size of the change, but not when you test whether a change happened.
Which discordant pairs should go in b and which in c?
By convention b counts pairs positive under the first condition only and c pairs positive under the second only, but the exact test is symmetric: swapping them gives the same p-value. Keep the convention anyway, because the direction of the effect is read from which count is larger, and a reader of your table will expect it.
Should I use the exact test or the chi-square version of McNemar's test?
The chi-square statistic is an approximation to the exact binomial calculation, and it is poor when there are few discordant pairs. In the worked example it gives 0.0455 without correction and about 0.0801 with it, either side of the exact 0.0768. With hundreds of discordant pairs the three versions agree closely, so the choice matters most in small studies.
What is the smallest number of discordant pairs that can give p below 0.05?
Six, and only if every one of them goes the same way. Five changes all in one direction give a two-sided p-value of 2 ÷ 2⁵ = 0.0625, while six give 2 ÷ 2⁶ = 0.03125. A study that expects only a handful of people to change their answer cannot reach significance however many concordant pairs it includes.
Can I use McNemar's test to compare two diagnostic tests on the same patients?
Yes. Let b be the patients positive on the first test only and c those positive on the second only. A small p-value then says the two tests differ in how often they call patients positive. It says nothing about which test is right; that needs a reference standard and measures such as sensitivity and specificity.
Why does the p-value come out as exactly 1 when b equals c?
When the split is perfectly even, the lower tail already includes the middle of the distribution, so doubling it counts some outcomes twice. With b = c = 5, the tail probability is 638 ÷ 1,024 = 0.623, which doubles to 1.246. A probability cannot exceed 1, so the result is capped, meaning the data show no imbalance at all.

How this page was produced

Published by
Quanta Calculator
Primary sources
3 cited below
Method
p = 2 × P[Binomial(b+c, 0.5) ≤ min(b,c)], capped at 1
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon