The formula
The average — more precisely the arithmetic mean — is the sum of all the values divided by how many there are:
The median is a second kind of "average": sort the numbers and take the middle one. When the count is even there is no single middle, so the median is the mean of the two central values. Because it ignores how far away the extremes are, the median resists outliers that would drag the mean up or down.
Worked example
For the set 4, 8, 15, 16, 23, 42 (n = 6):
Mean or median — which to use?
Use the mean when the data is roughly symmetric and you want every value to count, such as averaging test scores or daily temperatures. Reach for the median when the data is skewed or has outliers — incomes, house prices and response times are classic cases, where a few very large values would inflate the mean and make it misleading. Reporting both, alongside the range, gives a fuller picture of a data set than any single number.