The Mann-Whitney U Test, Explained

After reading this you will know when to reach for the Mann-Whitney U test instead of a t-test, how to compute U by hand from ranks, and how to read the p-value and the rank-biserial effect size.

What the test does

The Mann-Whitney U test asks a simple question: if you draw one value from group A and one value from group B at random, how often does the A value come out larger? If the two groups are identical, that should happen about half the time. If A values tend to sit above B values, the test detects it.

It works on ranks, not on the raw numbers. That makes it robust to skew and to outliers, and it means you never assume the data are normally distributed. A single extreme value that would wreck a mean barely moves a rank.

Consider five recovery times in days for treatment A: 12, 15, 11, 18, 14, and five for treatment B: 20, 22, 17, 25, 19. Every A value is smaller than every B value. The test should return the strongest possible signal, and below you will see it does exactly that.

When to use it, and when not to

Use the Mann-Whitney U test when you have two independent samples and you want to compare their distributions, but you cannot trust the normality assumption behind a two-sample t-test. Small samples, visibly skewed data, or ordinal outcomes such as Likert ratings all point to this test.

Do not use it when your two samples are paired (the same subject measured twice, or matched pairs). For that, use the Wilcoxon signed-rank test. For three or more independent groups, use the Kruskal-Wallis H test, which is the direct generalization. If your data really are roughly normal, the two-sample t-test has slightly more power and is the conventional choice.

The test compares whole distributions. It is only a clean test of medians when the two distributions have the same shape and spread. If A is shifted and also more spread out than B, a significant result tells you the distributions differ, not that one median is higher.

The formula and the intuition

Pool both samples, sort all the values, and assign ranks from 1 to n_A + n_B. Sum the ranks that belong to group A; call that R_A. The U statistic for A is:

U_A = R_A - \frac{n_A(n_A + 1)}{2}

Here n_A is the size of sample A, n_B is the size of sample B, and R_A is the sum of A's ranks. The subtracted term removes the minimum possible rank sum, so U_A counts the number of pairs (one A value, one B value) in which the A value wins.

The two U values are linked by a fixed identity, so you only need one:

U_A + U_B = n_A \cdot n_B

The reported statistic is usually the smaller of the two. For the p-value with larger samples, U is standardized. Under the null hypothesis its mean and standard deviation are:

\mu_U = \frac{n_A n_B}{2}, \quad \sigma_U = \sqrt{\frac{n_A n_B (n_A + n_B + 1)}{12}}

Then z = (U - \mu_U) / \sigma_U feeds a normal approximation. For small samples the calculator uses the exact distribution of U instead, which is more accurate when ties are absent.

A worked example with the demo data

Ranking treatments A and B

Take A = 12, 15, 11, 18, 14 and B = 20, 22, 17, 25, 19, so n_A = n_B = 5.

  1. Sort all ten values: 11, 12, 14, 15, 18, 17*, 19*, 20*, 22*, 25*. Written in true order they are 11, 12, 14, 15, 17, 18, 19, 20, 22, 25.
  2. Assign ranks 1 through 10. The five A values (11, 12, 14, 15, 18) get ranks 1, 2, 3, 4, 6. The five B values (17, 19, 20, 22, 25) get ranks 5, 7, 8, 9, 10.
  3. Sum A's ranks: R_A = 1 + 2 + 3 + 4 + 6 = 16.
  4. Apply the formula: U_A = 16 - \frac{5 \cdot 6}{2} = 16 - 15 = 1.
  5. Then U_B = 5 \cdot 5 - 1 = 24. The reported U is the smaller value, 1.

Why U = 1 and not 0? The single A value of 18 beats the single B value of 17. That is the only A-over-B pairing out of 25 possible pairs, so U_A = 1. For a two-sided test at 5 counts per group, U = 1 gives an exact p-value of about 0.016, below 0.05. You reject the null hypothesis: the two treatments differ.

Effect size: rank-biserial correlation

A p-value tells you whether the difference is detectable, not how large it is. The rank-biserial correlation fills that gap:

r = 1 - \frac{2 U}{n_A n_B}

Here U is the value tied to group A, and the product n_A n_B is the total number of A-versus-B pairs. The measure runs from -1 to +1. A value of 0 means A wins exactly half the pairings. A value near \pm 1 means one group dominates.

For the demo data using U_A = 1: r = 1 - \frac{2 \cdot 1}{25} = 1 - 0.08 = 0.92. That is a very large effect, which matches the fact that A loses 24 of 25 pairings.

The A values (11, 12, 14, 15, 18) claim the low ranks while B values (17, 19, 20, 22, 25) take the high ranks, with only 18 and 17 swapping order.

Two groups of five points sit on a number line. As group B slides right, its values stop overlapping A's, U falls toward 0, and the p-value drops below 0.05. When the groups fully overlap, U sits near 12.5 and the p-value is near 1.

Reading the results

Three numbers matter. Read them in order.

U
The count of pairings won by one group, from 0 to n_A n_B. Values near the midpoint n_A n_B / 2 mean no difference. For the demo, the midpoint is 12.5 and the observed U is 1, far from it.
p-value
The probability of a U this extreme or more if the distributions were identical. Compare it to your chosen threshold, commonly 0.05. The demo gives 0.016, so you reject the null.
Rank-biserial r
The size of the difference on a -1 to +1 scale. Rough guides: 0.1 small, 0.3 medium, 0.5 large. The demo's 0.92 is very large.

Report all three. A p-value alone can be significant with a trivial effect if the samples are large, or nonsignificant with a big effect if they are tiny.

Common mistakes

Do not apply this test to paired data. Feeding before-and-after measurements from the same subjects into a two-independent-sample test throws away the pairing and usually loses power. Use the Wilcoxon signed-rank test instead.

Watch for ties. When two values are equal they share the average of the ranks they would occupy. Many ties inflate the variance and make the normal approximation less accurate; the calculator applies a tie correction, but heavy ties still weaken the test.

Do not read a significant result as "the medians differ" unless the two distributions have similar shape. With different spreads the test can flag a difference in variability rather than in center.

Finally, the test needs both samples to be genuine independent draws. If group membership is confounded with time, batch, or operator, the U statistic will pick up that nuisance rather than the effect you care about.

Related tools on this site

If your data look roughly normal, compare the result against the t-test calculator. Check that assumption first with the normality test battery and the Levene's test for equal variances. For more than two groups use the Kruskal-Wallis H test or, for means, one-way ANOVA. If you have a test statistic in hand and only need the tail probability, the p-value calculator converts z, t, χ² or F values directly. For categorical outcomes, see the chi-square test of independence and Fisher's exact test.

Frequently asked questions

Is the Mann-Whitney U test the same as the Wilcoxon rank-sum test?

Yes. They are two names for the same procedure, derived independently. Mann and Whitney phrased it with U (pair counts); Wilcoxon phrased it with the rank sum. The p-values match exactly.

How small can my samples be?

It works with as few as a handful per group, but power is limited. With n_A = n_B = 3, the smallest possible two-sided p-value is about 0.10, so you can never reach 0.05 no matter how separated the groups are. Aim for at least 5 per group when you expect a real effect.

Does it test the mean or the median?

Neither directly. It tests whether one distribution is stochastically larger than the other. When the two distributions share a shape, that is equivalent to a shift in the median.

What if my two samples have very different sizes?

Unequal sizes are fine. The formula uses n_A and n_B separately, and the null mean n_A n_B / 2 already accounts for the imbalance.

Why is the reported U so small in the demo?

Group A loses 24 of the 25 possible pairings, so its win count is just 1. The calculator reports the smaller U, which signals strong separation; a U near 12.5 would signal no difference.