induwara.lk
induwara.lkStatistics · Goodness of fit

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.

By Induwara AshinsanaUpdated Jul 12, 2026
Kolmogorov–Smirnov test
NIST formulas · cross-checked
Test mode
4 values

Paste numbers separated by commas, spaces, or new lines.

4 values

The second independent group. Sizes need not match.

Try an example
Reject H₀ — the two samples come from different distributions (p = 0.0366 < α = 0.05).
Method: Two-sample K-S — D = maxₓ|F₁(x) − F₂(x)| over 8 pooled steps; asymptotic p from the Kolmogorov distribution with effective n = 2.
D statistic
1
max at x = 4
Asymptotic p-value
0.0366
small n · approximate
D critical (α = 0.05)
0.960323
D exceeds it → reject
Effective n
2
λ = √n·D = 1.4142
Effective sample size is small (2). The p-value is the asymptotic (large-sample) approximation and should be read as indicative. Prefer the critical-value verdict, or gather more data. For one-sample normality with μ and σ estimated from the data, use the Lilliefors test instead — standard K-S is anticonservative there.

Cumulative distributions

0.000.250.500.751.0018
F₁ (Sample A)F₂ (Sample B)Max gap D = 1

Critical values

αc(α)D criticalVerdict
0.11.22390.865409reject H₀
0.051.35810.960323reject H₀
0.011.62761.150904fail to reject

Your D = 1. A row rejects H₀ when D is larger than its critical value.

Parsed input
Sample A: n = 4, min = 1, max = 4Sample B: n = 4, min = 5, max = 8

Show working

  1. D⁺ = maxₓ (F₁ − F₂) = 1
  2. D⁻ = maxₓ (F₂ − F₁) = 0
  3. D = max(D⁺, D⁻) = 1 at x = 4
  4. Effective n = n₁n₂/(n₁+n₂) = 2
  5. At x = 4 the CDFs sit at 0 and 1.
  6. λ = √n · D = 1.414214
  7. p = Q_KS(λ) = 2·Σₖ (−1)^(k−1)·e^(−2k²λ²) = 0.036631

Cross-check: D from the main pass (1) and D recomputed by an independent method (1) agree ✓.

Sources cited

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.

  1. 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; scipy ks_2samp).
  2. 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⁻⁷).
  3. 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).
  4. 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

Two-sample — complete separation

A = 1, 2, 3, 4 (n₁ = 4) · B = 5, 6, 7, 8 (n₂ = 4)

  1. Every A value is below every B value, so at x = 4, F_A = 1.0 while F_B = 0
  2. D = |1.0 − 0| = 1.000000 (max separation at x = 4)
  3. Effective n = 4·4/8 = 2, λ = √2 · 1 = 1.414214
  4. p = 2·[e^(−4) − e^(−16) + …] ≈ 0.036631
  5. D_crit(0.05) = 1.3581·√(8/16) = 0.960324 → D = 1.000 > 0.960 → reject H₀

Two-sample — heavy overlap

A = 1, 2, 3, 4, 5 · B = 3, 4, 5, 6, 7 (n₁ = n₂ = 5)

  1. Gaps |F_A − F_B| at x = 1…7 are 0.2, 0.4, 0.4, 0.4, 0.4, 0.2, 0
  2. D = 0.400000 (first reached at x = 2)
  3. Effective n = 25/10 = 2.5, λ = √2.5 · 0.4 = 0.632456
  4. p = 2·[e^(−0.8) − e^(−3.2) + e^(−7.2) − …] ≈ 0.818621
  5. D_crit(0.05) = 1.3581·√(10/25) = 0.858913 → D = 0.400 < 0.859 → fail to reject H₀

One-sample vs Normal(0, 1) — small sample edge case

Sample = −1, 0, 1 (n = 3), reference standard Normal

  1. Φ(−1) = 0.158655, Φ(0) = 0.500000, Φ(1) = 0.841345
  2. D⁺ = max(1/3 − 0.158655, 2/3 − 0.5, 1 − 0.841345) = 0.174678
  3. D⁻ = max(0.158655, 0.5 − 1/3, 0.841345 − 2/3) = 0.174678
  4. D = 0.174678 — negatives and zero are handled like any value
  5. D_crit(0.10) = 1.2239/√3 = 0.706622 ≫ D → fail to reject (consistent with N(0,1))
  6. With n = 3 the asymptotic p-value is flagged unreliable, not shown as precise

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

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.