median() — The middle value

median(x)

Key idea

How to find the median in three steps

  1. Line your numbers up in order, from smallest to largest.
  2. If you have an ODD number of values, the median is the one in the middle. With n numbers, the middle one sits at position (n + 1) / 2 — e.g. 5 numbers → position 3.
  3. If you have an EVEN number of values, add the two middle numbers and divide by 2. The midpoint (n + 1) / 2 falls between them — e.g. 4 numbers → position 2.5, so average the 2nd and 3rd.

Definition

the k-th value once sorted
how many values
the median (middle value)

Where you'd use it

Frequently asked questions

What if there’s an even number of values?
The median is the average of the two middle values, so it may not be an actual data point.