Article — Median Calculator
Median Calculator: middle value, mean, and mode for any dataset
A median calculator finds the middle value of a sorted dataset. For an odd count, the median is the single middle value. For an even count, it is the average of the two middle values. The median is robust to outliers, unlike the mean, which is why income, home prices, and reaction-time data are reported as medians.
The calculation is fast in code (O(n log n) for the sort, O(1) for the lookup) but easy to get wrong by hand — the most common errors are forgetting to sort first and counting positions from zero instead of one. This calculator handles both edge cases automatically and shows the sorted data so you can verify.
What is a median calculator
A median calculator returns the middle value of a list of numbers. It is one of three measures of central tendency — the others being mean (average) and mode (most frequent value). All three give a single number meant to represent the "typical" value of a dataset, but they answer slightly different questions.
The median answers: "What value separates the higher half from the lower half?" The mean answers: "If we distributed the total evenly, what would each unit get?" The mode answers: "Which value occurs most often?" For symmetric data, all three agree closely. For skewed data, they diverge — and the gap is itself useful information.
The word "median" comes from Latin medianus, meaning "in the middle." It entered statistical usage in the 1880s, popularized by Sir Francis Galton, who argued that the median was the proper measure of central tendency for non-normal distributions — a position that was controversial at the time but is now standard practice.
The median formula
Two cases, depending on whether the data count is odd or even:
Sort x₁ ≤ x₂ ≤... ≤ xₙn odd median = x at position (n+1)/2n even median = (x at n/2 + x at n/2+1) ÷ 2Example with odd count: data = 12, 8, 21, 5, 33, 17, 9. Sort: 5, 8, 9, 12, 17, 21, 33. n = 7, middle position is (7+1)/2 = 4. The 4th value is 12. Median = 12.
Example with even count: data = 10, 15, 20, 25. Already sorted. n = 4, take the average of positions 2 and 3 (15 and 20). Median = 17.5.
Median vs. mean vs. mode
Each measure has a use case:
- Mean (average): Sensitive to every value, including extremes. Best for symmetric, normally-distributed data. The basis for variance and standard deviation.
- Median (middle): Robust to outliers and skew. Better for income, home prices, reaction times, and any right-skewed data.
- Mode (most frequent): The only measure that works for non-numeric categorical data. Less useful for continuous data where exact duplicates are rare.
A revealing dataset: 25, 28, 30, 32, 1000. Mean = 223. Median = 30. Mode: no mode (all unique). The single $1,000 value pulls the mean to 223, far from the "typical" value of about 30. The median resists this distortion.
When to use median
Several real-world domains default to median rather than mean:
- Household income: Right-skewed by top earners. US median household income was about $80,610 in 2023 (US Census ACS); mean about $114K. The median better represents typical American experience.
- Home prices: A few mansion sales distort the mean. Real-estate sites and the FHFA report median sale prices for the same reason.
- Test scores: Educators use medians to avoid distortion from a small number of very low or very high scorers.
- Reaction times: Psychology and HCI use median RT — the right tail of slow responses (distraction, blinks) skews means upward.
- Wait times: Hospital triage and customer service measure median wait time. A few extreme delays should not define typical experience.
If you ever see "average" reported without specifying mean or median, assume mean and ask yourself whether the data is skewed. Headlines about "average household income" usually report the mean, which is consistently higher than the typical experience.
Median with outliers
The median is famously robust to outliers, but "robust" is not the same as "unaffected." Adding a single extreme value does not move the median if the count stays odd or the two middle values stay the same. But adding enough extreme values, or adding values that change which positions count as "middle," does shift the median.
Quantitatively: the breakdown point of the median is 50%. You can change up to half the data values arbitrarily and the median remains stable, as long as the remaining values still bracket the original median. The mean's breakdown point is 0% — a single value can move the mean as far as you like.
Median of grouped data
When you only have histograms or binned survey data, individual values are gone. The median estimate uses linear interpolation within the median class — the class that contains the n/2-th observation.
Median = L + (n/2 - F)/f × wL = lower boundary of median classF = cumulative frequency before classf = frequency of median classw = class widthThis is the standard formula in introductory statistics and is what spreadsheet plug-ins like Excel's QUARTILE and Python's pandas use under the hood for binned data.
Median in real-world statistics
The US Census Bureau reports median household income annually as the primary measure. The reason is concrete: the top 1% of earners have incomes 100 times the median, which distorts the mean by tens of thousands of dollars. Policy decisions based on the mean would misrepresent the typical American household.
Similarly, the National Association of Realtors reports median home prices, the BLS reports median wages, and the OECD reports median inequality measures internationally. When you see "the average" in a finance or social-science context, it is often the median in disguise — or, sometimes, the mean used carelessly.
If you have three datasets and the medians are 10, 20, and 30, the median of the combined dataset is not 20. Medians do not aggregate linearly. To get the combined median, you must combine the raw data and re-sort. This trips up dashboard builders who try to weighted-average median values from sub-groups.
Common median mistakes
The most common error is forgetting to sort the data first. The median is undefined for unsorted data — you must sort. Spreadsheet formulas like MEDIAN() and statistical software handle this internally, but hand calculations skip it surprisingly often.
The second error is confusing position with value. For data 5, 10, 15, 20, 25, the middle position is 3 and the middle value is 15. People sometimes report "3" as the median, which is the index, not the value.
The third error is using the median for variance or standard deviation calculations. Both of those measures are built on the mean. Substituting the median produces something called the "median absolute deviation" (MAD), which is a different statistic with different interpretation.