Kolmogorov–Smirnov (K-S) Test Calculator
Paste two samples to check if they share a distribution, or test one sample against a Normal, Uniform, or Exponential model. Get the D statistic, the asymptotic p-value, critical values, and an ECDF chart — all in your browser, no signup.
How it works
The Kolmogorov–Smirnov test compares whole distributions through their empirical cumulative distribution functions (ECDFs). For a sample of size n, the ECDF at x is the fraction of observations at or below x — a step function that rises by 1/n at each data point. The test statistic D is the single largest vertical gap between the ECDFs being compared. Because both step functions only change at observed values, that maximum is always attained at one of the data points, so one sorted pass finds it exactly.
- Two-sample D. Pool and sort all n₁ + n₂ values, walk them in order tracking F₁ and F₂, and take
D = maxₓ |F₁(x) − F₂(x)|. The calculator marks the x where the gap is widest (NIST §1.3.5.16; scipyks_2samp). - One-sample D. Sort the sample x₍₁₎ ≤ … ≤ x₍ₙ₎ and compare its ECDF to the specified reference CDF F₀ (Normal, Uniform, or Exponential):
D⁺ = maxᵢ(i/n − F₀(x₍ᵢ₎)),D⁻ = maxᵢ(F₀(x₍ᵢ₎) − (i−1)/n), and D = max(D⁺, D⁻). The Normal CDF uses Φ(z) = ½·erfc(−z/√2) with the Numerical Recipes erfc() fit (error < 1.2×10⁻⁷). - Asymptotic p-value. With effective size n (= n₁n₂/(n₁+n₂) for two samples, = n for one), the scaled statistic λ = √n·D follows the Kolmogorov distribution, and the p-value is its tail:
p = 2·Σₖ (−1)^(k−1)·e^(−2k²λ²). The alternating series converges geometrically; the tool sums it until the terms are negligible (Kolmogorov 1933; NIST §1.3.5.16). - Critical values. The two-sided large-sample critical value is
D_crit(α) = c(α)·√((n₁+n₂)/(n₁n₂))(two-sample) or c(α)/√n (one-sample), with c(α) = √(−½·ln(α/2)). This reproduces the standard table: c(0.10)=1.2239, c(0.05)=1.3581, c(0.01)=1.6276. Reject H₀ when D exceeds D_crit(α).
The p-value here is the large-sample approximation. For small effective n it is only indicative, so the tool shows the effective n and labels the result accordingly. For a one-sample normality check where μ and σ are estimated from the same data, standard K-S is anticonservative — use the Lilliefors test (Lilliefors, 1967) instead. Every calculation runs client-side, so nothing you paste leaves your device.
Worked examples
Frequently asked questions
Sources & references
- NIST/SEMATECH e-Handbook of Statistical Methods §1.3.5.16 — Kolmogorov–Smirnov Goodness-of-Fit Test
- SciPy — scipy.stats.ks_2samp / kstest (reference implementation for D and the asymptotic p-value)
- Smirnov, N. (1948) — Table for estimating the goodness of fit of empirical distributions (Annals of Mathematical Statistics)
- Lilliefors, H. (1967) — On the Kolmogorov–Smirnov Test for Normality with Mean and Variance Unknown (JASA)
The formulas and all three worked examples on this page were last cross-checked against these sources — and against SciPy reference cases — on 2026-07-12.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.