The upper fence formula
The upper fence is the threshold above which a data point is treated as a potential outlier. It comes from John Tukey's boxplot method and is defined entirely by the two outer quartiles of your data:
Upper fence = Q3 + 1.5 × IQR, where IQR = Q3 − Q1
Q1 is the first quartile (the 25th percentile — 25% of the data lies below it), and Q3 is the third quartile (the 75th percentile). The interquartile range (IQR) is the width of the middle 50% of the data. The upper fence sits one and a half IQRs above Q3. Its mirror image, the lower fence, is Q1 − 1.5 × IQR. Any observation above the upper fence or below the lower fence is flagged as a potential outlier.
Why the fence is needed
Real datasets often contain a few extreme values caused by measurement error, data-entry mistakes, or genuinely rare events. Those values can distort the mean, inflate the standard deviation, and mislead a model. The fence gives an objective, reproducible rule for spotting them that does not depend on the mean or standard deviation, so it is robust even when the data is skewed. It is the same rule that draws the "whiskers" on a boxplot: each whisker extends to the most extreme data value that still lies inside the fences, and anything beyond is plotted as an individual outlier point.
Why the multiplier is 1.5
The 1.5 multiplier is Tukey's convention. For data drawn from a normal distribution, Q1 ≈ −0.6745σ and Q3 ≈ +0.6745σ, so the IQR ≈ 1.349σ and the upper fence lands at about 2.698σ above the mean. Only about 0.35% of a normal distribution lies beyond that on each side (roughly 0.7% total across both fences), so the rule flags clear extremes without over-flagging ordinary variation. When you want to isolate only the most severe "far out" values, replace 1.5 with 3.0; that pushes the fence to about 4.72σ, beyond which normal data almost never falls.
A worked example
Suppose a dataset has Q1 = 25 and Q3 = 75. Then IQR = 75 − 25 = 50, and the upper fence = 75 + 1.5 × 50 = 75 + 75 = 150. The lower fence = 25 − 75 = −50. So any value above 150 (or below −50) is a potential outlier. If the largest value in the data were 148, there would be no high outliers; if it were 200, that 200 would be flagged.