Step-by-step
- Collect the numbers in your data set.
- Arrange the values from smallest to largest.
- If there is an odd number of values, select the middle value.
- If there is an even number of values, calculate the mean of the two middle values.
- Check that every intended value was included exactly once.
Median formula for even-sized data
When the number of observations is even, add the two central values and divide their sum by two. For an odd-sized set, the median is the single central value after sorting.
Median versus average
The arithmetic mean uses every value and can be pulled by extreme values. The median depends on the middle position, so it can better represent skewed data such as home prices or response times.
Worked examples
For 3, 9, 1 and 7, sorting gives 1, 3, 7, 9. There are four values, so the median is the mean of 3 and 7, which is 5.
With an outlier the difference is clear. For 20, 22, 25 and 500, the mean is 141.75 but the median is 23.5, which describes the typical value far better.
Finish the task with DevUtilityKits
Use the relevant online utility, check the result, and continue with your development workflow.
Open Median Calculator →