Quartiles and IQR

Introduction

Welcome back to Measuring Spread with Range and IQR! You are now on the second of five lessons in this course, and you have already built a solid foundation. In the previous lesson, we computed the range and saw its biggest weakness: because it depends on only the maximum and minimum, a single extreme value can inflate it dramatically. That raises an important question: is there a way to measure spread that is far less sensitive to the extremes? The answer is yes, and it is what this lesson is all about. Here we introduce quartiles and the interquartile range (IQR), two tools that focus on the middle of the data and let values at the edges fade into the background.

Zooming In on the Middle

Think of the range as measuring a room from wall to wall. That gives you the total width, but it reveals nothing about where the furniture sits. To understand how values are actually arranged, we need landmarks inside the dataset, not just at its edges.

Quartiles give us exactly those landmarks. They divide a sorted dataset into four equal parts, marking the boundaries at the 25%, 50%, and 75% points. By measuring the distance between the 25% and 75% marks, we capture the spread of the central bulk of the data while letting extreme highs and lows stay out of the picture.

A clean number line in flat vector style on a warm off-white background, with evenly spaced data points divided into four equal quarters by three vertical markers labeled Q1, Median, and Q3 in charcoal text, the two middle quarters shaded in a muted teal accent, with thin consistent outlines and minimal spacing

What Are Quartiles?

Once a dataset is sorted from smallest to largest, three values split it into four quarters:

  • Q1 (the first quartile) sits at the 25% mark. About one-quarter of the data falls below this value.
  • Q2 (the second quartile) is the median, the 50% mark. As you may recall from the previous course, the median divides the data in half.
  • Q3 (the third quartile) sits at the 75% mark. About three-quarters of the data falls below this value.

Here is the core idea: Q1 is the median of the lower half of the data, and Q3 is the median of the upper half. The specific approach we use in this course is called the median-exclusive method. When the dataset has an odd number of values, we set the overall median aside before finding Q1 and Q3 — it does not belong to either half. The next section walks through the full procedure.

Finding Quartiles Step by Step

Follow these steps every time you need to find quartiles:

  1. Sort the data from smallest to largest.
  2. Find the median (Q2). If the count is odd, the median is the single middle value. If the count is even, the median is the average of the two middle values.
  3. Form the lower half. Take every value that falls below the median position. If the count is odd, do not include the median itself.
  4. Form the upper half. Take every value that falls above the median position. Again, exclude the median if the count is odd.
  5. Find Q1 as the median of the lower half.
  6. Find Q3 as the median of the upper half.

The critical detail is in steps 3 and 4: when the count is odd, the median sits alone in the center and does not belong to either half. That is what makes the method median-exclusive. When the count is even, no value needs to be excluded, and the data splits cleanly into two equal halves.

Worked Example: Odd Number of Values

Worked Example: Even Number of Values

Computing the Interquartile Range

Why the IQR Resists Outliers

Conclusion and Next Steps

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal