The triangle inequality is the statement that the straight-line path between two points is never longer than a path that bends through some intermediate point. On a flat piece of paper it says that the direct edge of a triangle is always shorter than (or equal to) the sum of the other two edges. On the real line — where everything lies on a single axis and "distance" collapses to the absolute value of a difference — it becomes the crisp algebraic identity
for any three real numbers a, b, c. The visualisation below lets you drag those three numbers around on a number line and watch the two quantities side by side. One is the length of the direct hop from a to c. The other is the length of the two-hop detour from a through b to c. The detour is never shorter. When b happens to lie exactly between a and c, the two lengths are equal; in every other configuration, the detour is strictly longer.
The widget
Reading the picture
Three things happen in the panel as you drag.
The blue bar on top spans from \min(a, c) to \max(a, c). Its length is |a - c|, the direct distance between the two outer points. It does not depend on where b sits — moving b alone never changes the blue bar.
The two orange bars underneath represent the two legs of the detour. The upper orange strip is |a - b|, the distance from a to b. The lower orange strip is |b - c|, the distance from b to c. Together, their lengths sum to |a - b| + |b - c|.
The inequality
is the statement that the blue bar is never longer than the two orange bars combined. If you try to make the detour shorter than the direct hop — by sliding b cleverly — you will fail. The best you can ever do is tie, and you tie exactly when b falls somewhere inside the closed interval [\min(a, c), \max(a, c)].
Why the inequality holds
On the real line the proof is three lines. Start from the definition of absolute value as a distance and use the identity (a - c) = (a - b) + (b - c).
The middle step is just algebra — the two b's cancel. The final step is the one-dimensional triangle inequality |x + y| \le |x| + |y|, which you can prove by squaring both sides (both are non-negative) and reducing to 2xy \le 2|xy|. So the three-point statement is really the two-term statement in disguise, applied to x = a - b and y = b - c.
When does equality hold?
Squaring |x + y|^2 = |x|^2 + 2xy + |y|^2 and (|x| + |y|)^2 = |x|^2 + 2|x||y| + |y|^2, the two are equal precisely when xy = |x||y| — that is, when x and y have the same sign (or at least one is zero). Translating back, x = a - b and y = b - c share a sign exactly when b lies between a and c (inclusive). If a < c, that means a \le b \le c; if a > c, it means c \le b \le a.
The widget makes this concrete. Park a at -6 and c at 7. As long as you keep b anywhere in [-6, 7], the readout stays green and the two sums agree. Nudge b outside that interval — say, to b = 8 — and the orange bars overshoot, a gap appears, and the readout flashes red.
Why this warm-up matters
In the full two-dimensional picture, the triangle inequality says \|\vec{AC}\| \le \|\vec{AB}\| + \|\vec{BC}\| for any three points A, B, C in the plane. Equality holds when the three points are collinear and B lies on the segment AC. On the real line, all three points are automatically collinear — they already live on a single axis — so the equality case is the generic one whenever B sits between A and C.
This is why the one-dimensional version is the simplest possible instance of the triangle inequality and the right place to build intuition. Every piece of the general idea is already visible: the "direct path" is the shortest, detours cost nothing only when they don't actually leave the path, and strict detours strictly cost.
The triangle inequality is also the defining property of a metric. A function d(x, y) counts as a distance function on a set X if it is non-negative, symmetric (d(x, y) = d(y, x)), zero exactly when x = y, and satisfies d(x, z) \le d(x, y) + d(y, z) for all three points. The one-dimensional absolute-value distance d(x, y) = |x - y| passes all four tests, and the widget above is a hands-on demonstration of the last and most interesting one. Once you believe the inequality for three points on a line, the generalisation to the plane, to three-dimensional space, to function spaces, and to abstract metric spaces is just a change of what "distance" means — the algebraic shape of the inequality is identical.
Things to try
Slide b slowly from far to the left of both a and c, through them, and out to the far right. Watch the gap between the two sums shrink as you approach the interval [a, c], collapse to zero once you enter it, stay at zero throughout, and reopen as you exit on the other side. The "green zone" is a closed interval, and it is exactly the convex hull of \{a, c\}.
Try setting a = c. The direct distance is zero, so the inequality reads 0 \le 2|a - b|, which is trivially true, with equality iff b = a too.
Set b = a. The first leg vanishes; the detour reduces to |a - c|, the same as the direct hop, and you get equality for free. The same happens at b = c.
Finally, push b far away — say b = 10 with a = -5, c = 5. The detour becomes 15 + 5 = 20 while the direct path stays at 10. The detour is twice the direct path, a vivid reminder that going out of your way on the real line really does cost you every unit of displacement twice.
Related visualisations
- |x − c| < r as a Ball of Radius r Around c — Absolute-Value Inequality Visualiser — the "distance from a centre" reading of absolute value, which powers the triangle-inequality proof.
- Interval Builder: Drag Endpoints, Toggle Open-Closed, Watch the Notation — the interval [\min(a, c), \max(a, c)] is exactly the "green zone" in the widget above.