Mann-Whitney U Calculator

Rank-sum test with exact p-values and ties handled.

  • Exact p, small samples
  • Ties handled
  • Effect sizes included
A small rounded clay table with two rows of soft clay beads graded from small to large and interleaved in the middle, lit by soft daylight.

The guide

The Mann-Whitney test counts pairs, and exact counting beats a bell curve when samples are small

Swapping values for ranks makes this test hard to sway with one wild number, but its p-value, its ties and its claim about medians all need careful handling.

  • 49/143 exact two-sided p for the thirteen-value tied example
  • 0.3140 normal p for it, with the tie correction
  • 0.3173 normal p for it if the ties are ignored
  • 1/35 exact p when 1 2 3 4 are set against 5 6 7 8
  • 0.0209 normal p for that split, about 27 percent too small
Read the full guide Fold the guide 7 min · 13 sources

Two lists of numbers, one question: do the values in one list tend to sit higher than the values in the other? A t-test answers a different question, about means, and it listens closely to every value, including the wild one.

The Mann-Whitney U test, also called the Wilcoxon rank-sum test, tests whether randomly chosen values from two populations have the same distribution. It is a nonparametric test for independent samples. Matched or paired samples belong to a neighbour, the Wilcoxon signed-rank test, which looks at the differences within each pair. The choice between them is made by how the data were collected, not by how they look.

What the ranks keep, and what they throw away

Ranking is simple. Put both samples into one list, sort it, and number the positions from 1. Equal values need a rule. The usual one gives each tied value the midpoint of the positions it spans, so the values 3, 5, 5, 5, 5, 8 receive the ranks 1, 3.5, 3.5, 3.5, 3.5, 6. SciPy calls this the average method, and the general article on ranking calls it fractional ranking.

Once values become ranks, size stops mattering. A top value of 14 and a top value of 1400 both become the last place in line. One mismeasured entry cannot drag the result, which is why the test is described as less likely than the t-test to spuriously indicate significance because of outliers.

The price is the spacing between values. Ranks cannot tell a near miss from a mile. When the data really are normal the price is small: the test’s asymptotic efficiency against the t-test is 3 divided by pi, about 0.95. When the data are skewed or heavy tailed, the ranks often do better.

Take a worked example that the page loads at the start. Group A holds 3, 5, 5, 7, 9, 12 and Group B holds 4, 5, 8, 10, 11, 11, 14. Thirteen values, three of them equal to 5 and two equal to 11. The ranks for Group A are 1, 4, 4, 6, 8 and 12. The ranks for Group B are 2, 4, 7, 9, 10.5, 10.5 and 13.

The rank sums are R1 = 35 and R2 = 56. Together they make 91, which is 13 times 14 divided by 2, as it must be. That quick check catches a slipped rank before it spreads into everything else.

U counts the pairs one group wins

The statistic follows from the rank sum. For the first sample, U1 = R1 minus n1 times (n1 + 1) divided by 2, and U2 is built the same way for the second. Here U1 = 35 - 21 = 14 and U2 = 56 - 28 = 28. The two always add up to n1 times n2, and 14 + 28 = 42 = 6 times 7.

Why does that number matter? Because U is a tournament score. Pair every value of A with every value of B, forty-two pairs in all. A holds the larger value in 13 pairs, B holds the larger value in 27, and 2 pairs are equal. Count each equal pair as half a win for each side and the scores are 14 and 28, exactly the two U values.

Dividing U1 by n1 times n2 gives the common language effect size, here 14 / 42 = 0.333: the chance that a random A value beats a random B value, ties counting half. The same idea is called the probability of superiority, and one early illustration used the chance that a random man is taller than a random woman. The rank-biserial correlation is r = 2f - 1 = -0.333, the share of pairs favouring A minus the share favouring B. A split of 90 pairs against 10 gives 0.80.

Many reports quote only the smaller U, and some forget to say which group it belongs to. Without that label the direction of the effect is lost. This page always prints U1 for the first sample and U2 for the second, and it gives the effect sizes for the first.

Counting beats the bell curve when samples are small

If the group labels meant nothing, every way of dealing the thirteen ranks into a set of six and a set of seven would be equally likely. There are 1,716 such ways. The exact p-value counts the ways whose rank sum is at least as far from its mean as the observed one. For the example, 588 of the 1,716 are that far out, so p = 588/1716, which reduces to 49/143, or 0.3427.

This is a permutation test: the statistic is computed under every rearrangement of the data, which makes the test exact rather than approximate. Because the count deals out the actual tie-averaged ranks, doubled so that 10.5 becomes the whole number 21, it stays valid when values are tied. Tables for sample sizes of eight or less were already published in the 1947 paper by Mann and Whitney; a computer now does the same counting for any size this page accepts.

The usual shortcut is a bell curve. Under no difference, U has mean n1 times n2 divided by 2, which is 21 here. Its standard deviation without ties is the square root of n1 n2 (n + 1) / 12, which is 7. With ties the formula subtracts a term built from the sizes t of the tied groups, the sum of t cubed minus t. For the example the sum is 24 + 6 = 30 and the standard deviation drops to 6.95.

The z value is (14 - 21) / 6.95 = -1.007, and the two-sided normal p-value is 0.3140. Ignore the ties and z is exactly -1 and p is 0.3173. All three numbers, 0.3427, 0.3140 and 0.3173, tell the same story here, yet they are not the same number, and the gap grows as samples shrink or ties pile up.

A source that treats the approximation as fairly good above about 20 values is describing a rule of thumb, not a guarantee. Try 1 2 3 4 against 5 6 7 8, a complete separation. Only two of the 70 ways to split the ranks are as extreme, so the exact two-sided p is 2/70 = 1/35 = 0.0286. The normal curve gives z = -2.309 and p = 0.0209, about 27 percent too small. For six against six with no overlap the error flips: the exact p is 2/924 = 0.0022 and the curve says 0.0039.

Software defaults add a wrinkle. SciPy documents that its asymptotic method corrects for ties, that its exact method makes no correction for ties, and that its automatic choice uses the exact method only when a sample has at most eight values and there are no ties. A tied data set therefore falls back to the normal curve even when it is tiny. Counting the real ranks removes that limit.

Exact counting is not free. The number of splits grows fast: two samples of 60 values already allow about 9.7 times 10 to the power 34 of them, far beyond the 9,007,199,254,740,991 that an ordinary number holds without losing digits. A BigInt keeps every digit, and the dynamic programme that adds up the counts runs in a web worker, a background thread, so the page stays responsive. The tail of the normal curve comes from the complementary error function, whose definition appears in the NIST handbook of mathematical functions.

What a small p-value does not say

Here is the claim that most often goes wrong. A significant Mann-Whitney result is not, in general, a statement about medians. Only under strict assumptions, such as a pure shift of one distribution relative to the other, can it be read as a difference in medians. Without them it is possible to find samples whose medians are equal while the test returns a small p-value. If a test of medians is what you need, quantile regression asks that question directly.

What the test does detect is a tendency for one sample to be larger. Mann and Whitney framed the alternative as one distribution being stochastically greater than the other, a statement about probabilities of exceeding any given value. The Hodges-Lehmann estimate pairs naturally with it under a shift: it is the median of all the differences between a value in one sample and a value in the other.

There are limits on every side. The observations must be independent of one another, and at least ordered. If the spreads or the shapes differ a great deal, a significant result may reflect those differences rather than a shift, and the Brunner-Munzel test has been suggested for the case where the distributions cannot be assumed equal under the null hypothesis.

The test cannot handle matched pairs, more than two groups, or any question about cause. A tiny p-value in a survey says the groups differ in distribution. It does not say why.

To reproduce the example, paste 3 5 5 7 9 12 into the first box and 4 5 8 10 11 11 14 into the second. You should see U1 = 14, U2 = 28, 588 of 1716 splits, an exact p of 0.3427 and normal p-values of 0.3140 and 0.3173 on the tie card. Now change the 14 to 1400. Nothing moves, because the ranks do not.

Every figure above was also checked outside the page, with exact fraction arithmetic from Python’s fractions module, a brute-force listing of all the splits, and SciPy’s routines for the cases they cover. A calculator that shows its ranks lets you do the same check by hand.

Sources

Every source consulted for this guide. Links checked November 10, 2026.

  1. Mann-Whitney U test Wikipedia
  2. Wilcoxon signed-rank test Wikipedia
  3. Ranking Wikipedia
  4. Permutation test Wikipedia
  5. Probability of superiority Wikipedia
  6. Hodges-Lehmann estimator Wikipedia
  7. Stochastic ordering Wikipedia
  8. scipy.stats.mannwhitneyu SciPy documentation
  9. scipy.stats.rankdata SciPy documentation
  10. Definitions of the error functions (DLMF 7.2) NIST Digital Library of Mathematical Functions
  11. BigInt MDN Web Docs
  12. Web Workers API MDN Web Docs
  13. fractions - Rational numbers Python Software Foundation