Two classes, one quiz
A tutor teaches the same statistics quiz twice a week. Morning class, afternoon class, same twelve questions. The morning average came out at 69. The afternoon average came out at 62.5. Seven marks apart. Is the afternoon class really weaker, or did the morning class just have a good day? A difference in means is one way to ask. The Kolmogorov-Smirnov test asks a sharper question: line the two classes up from lowest to highest and find the widest gap between them. That gap is the whole test.
What D actually measures
Take your sample and sort it. Walk from the smallest value to the largest and count how many values you have passed. That count, divided by n, is the empirical distribution function: a staircase that climbs from 0 to 1. Now lay the curve you are testing against over the same staircase. A normal curve, or the staircase of a second sample. D is the biggest vertical gap between the two, anywhere along the line. It runs from 0, a perfect match, to 1, no overlap at all. A small D says the sample hugs the curve. A large D says it wanders off somewhere, and the place it wanders off tells you what kind of difference you are looking at.
Three versions, one idea
The test comes in three versions and the calculator above runs all three. The first tests one sample for normality: it fits a normal curve with your sample mean and standard deviation, then measures the gap. That version has a special name, the Lilliefors test, because fitting the curve from the same data changes the maths. The second tests one sample against a normal distribution you name in advance, mean and standard deviation fixed before you look at the data. The third compares two samples with each other, no curve involved at all. Pick the version that matches the question you actually asked. The most common mistake in this whole area is running the second version with numbers estimated from the sample. That is the Lilliefors situation, and the ordinary p-value will come out too generous. Use the first version there.
Twelve exam marks: 62, 68, 71, 65, 74, 69, 72, 66, 70, 73, 67, 71. Mean 69.0, sample standard deviation 3.54. The fitted normal curve runs through them, and the widest gap between the staircase and the curve is D = 0.1305, at the mark 71, where the staircase sits 0.1305 above the curve. The Lilliefors p-value is 0.8281. Nothing here argues against normality, and the test says so plainly. The Shapiro-Wilk test on the same twelve marks gave W = 0.9717 with p = 0.9281, the same verdict from a more sensitive instrument. When both tests agree, the conclusion is easy to trust. When they disagree, the Shapiro-Wilk result usually carries more weight for normality, because it was built for that one job.
Worked example: do the two classes differ?
Same twelve morning marks against the afternoon class: 58, 61, 64, 59, 66, 63, 60, 65, 62, 67, 61, 64. Mean 62.5. Lay the two staircases over each other. At the mark 65, only 2 of the 12 morning students scored 65 or below, while 10 of the 12 afternoon students did. That is a gap of 0.6667, and it is the widest gap anywhere: D = 0.6667. The exact p-value is 0.0079. At any usual alpha the classes differ. The gap sits in the middle of the marks, not the tails, which is what a shift in the whole class looks like. A difference in means would have said the same thing here. The KS test adds the shape: the afternoon class is not just lower on average, it is lower almost everywhere.
The same data, one bad apple
Eight delivery times from a courier depot: 12, 14, 13, 15, 12, 14, 13 and 38 minutes. Seven ordinary runs and one van stuck in traffic. The Lilliefors test gives D = 0.4371 with p < .001. Normality fails, and the gap that convicts it sits at 15 minutes, where the staircase jumps ahead of the curve. The Shapiro-Wilk test agreed, with p = 0.0000223. Both tests are really pointing at the same thing: the 38. Before reaching for a different test, look at the van, the route, and whether that 38 belongs in the analysis at all.
A specified distribution, checked by hand
Sometimes the distribution is fixed before the data arrive. A machine fills jars to a claimed normal distribution with mean 500 grams and standard deviation 5. Ten jars weigh 500, 502, 498, 501, 499, 503, 497, 500, 501 and 499 grams. Against the claimed N(500, 5), D = 0.2743, widest at 503 grams on one side and 497 on the other, with p = 0.38. The fills are consistent with the claim. Note the p-value here comes from the standard asymptotic approximation with the finite-sample correction, which sits within about 0.01 of the exact value at this sample size. The two-sample p-values on this page are exact.
Reading the p-value without fooling yourself
A p-value of 0.06 is not a pass. It says the sample was too small, or too close to the curve, to convict. The numbers 1 to 10, perfectly uniform, sail through the Lilliefors test with D = 0.0955 and p = 0.9982. A small sample has little power to detect a wrong shape, so report the D, show the plot, and call the check inconclusive rather than clean. Power grows with n, and the test is honest about that: the same D that is meaningless at n = 10 is damning at n = 100.
Running the ordinary KS test with a mean and standard deviation estimated from your own sample. The test assumes the curve was fixed in advance. When you estimate it from the data, the curve hugs the staircase too closely, D shrinks, and the p-value comes out too big. That is exactly the mistake the Lilliefors correction exists to fix. If the mean and SD came from your sample, use the normality version above.
KS or Shapiro-Wilk?
For normality alone, Shapiro-Wilk is usually the stronger test. It was built for that one question and it notices bends the KS test walks past. The KS test earns its place in two other spots. It compares two samples directly, which Shapiro-Wilk cannot do at all. And it tests against any distribution, not just the normal: uniform, exponential, a curve from a textbook. If the question is "are these data normal", run Shapiro-Wilk and let the KS test confirm. If the question is "do these two groups differ" or "does this sample match that distribution", the KS test is the right tool.
If the test rejects
First, find the cause. Skew often yields to a log transform. An outlier may be a data entry slip, or a real event worth keeping and explaining. A shape with two humps usually means two groups mixed together, and no transform fixes that: split the groups first. When the shape stays non-normal, rank tests drop the requirement entirely. The Mann-Whitney U test replaces the two-sample t-test, and the Wilcoxon signed-rank test replaces the paired one. And when the sample is large, the t-test leans on the central limit theorem: means of large samples behave normally even when the raw data do not, so a mild departure at n = 200 matters far less than the same departure at n = 12.
Where this test sits in your workflow
Check normality before any test that assumes it: the one-sample t-test, the two-sample t-test, ANOVA. Compare two samples when you want the whole shape, not just the means. And check a claimed distribution before building on it, the way the jar weights were checked above. Check it alongside equal variances, where the Levene test calculator does the same gatekeeping job for spread. The guide to choosing a statistical test puts the whole family side by side. Run the check, read the plot, then run the test you actually wanted. That order keeps the p-value honest.
Frequently asked questions
What does the Kolmogorov-Smirnov test actually compare?
Your sample, drawn as a staircase that climbs from 0 to 1, against a curve or a second staircase. D is the biggest vertical gap between them. A small D means the sample tracks the curve closely; a large D means it wanders off somewhere.
Which should I use for normality, KS or Shapiro-Wilk?
Shapiro-Wilk, usually. It was built for that one question and notices bends the KS test walks past. Use the KS test when you compare two samples, or when the distribution you test against is not normal. Run both when you can: agreement is easy to trust.
Why can't I run an ordinary KS test with my sample mean and SD?
Because the test assumes the curve was fixed before the data arrived. Estimating the mean and SD from the same sample pulls the curve toward the staircase, shrinks D, and inflates the p-value. The Lilliefors version of the test corrects for exactly that, so use it when the parameters came from your sample.
What sample size does the KS test need?
It works at any size, but power grows with n. The Lilliefors version here needs at least 5 values, matching R. The two-sample version needs at least 2 values in each group. Below n = 10, only a large departure will come back significant, so read a non-significant result as inconclusive rather than clean.
My p-value is 0.06. Are my data normal?
No verdict either way. You failed to reject normality, which is not the same as proving it. Report the D, show the histogram, and say the check was inconclusive. The numbers 1 to 10, perfectly uniform, pass the Lilliefors test with p = 0.9982, which shows how little a small sample can prove.