What the formula says
A line is written ax + by + c = 0 and a point is (x₀, y₀). The shortest distance from the point to the line is
d = |ax₀ + by₀ + c| / √(a² + b²)
Holds when a and b are not both 0. If they are, ax + by + c = 0 is not a line, and the denominator is 0.
The top is the left side of the line’s equation with the point put in. It is 0 exactly when the point is on the line, and its size says how far off the line the point is, measured in units of √(a² + b²). The bottom turns that into a length.
Why it works
The vector (a, b) is perpendicular to the line, so the shortest way from the point to the line runs in that direction. Move from (x₀, y₀) a distance t along (a, b) to the point (x₀ + ta, y₀ + tb), and ask for that point to be on the line:
- a(x₀ + ta) + b(y₀ + tb) + c = 0
- t(a² + b²) = −(ax₀ + by₀ + c)
- t = −(ax₀ + by₀ + c) / (a² + b²)
The step taken has the length |t| · √(a² + b²), which is the distance. Putting t in gives the formula. The sign of t is why the absolute value is needed: it is positive on one side of the line and negative on the other.
Worked examples
A point on one side. The line 3x + 4y − 10 = 0 and the point (5, 5). Here a = 3, b = 4, c = −10, so the top is |3 · 5 + 4 · 5 − 10| = |25| = 25 and the bottom is √(9 + 16) = 5. The distance is d = 25 / 5 = 5. The perpendicular meets the line at (2, 1).
The same line, the other side. The point (−3, −5): the top is |3 · (−3) + 4 · (−5) − 10| = |−39| = 39, so d = 39 / 5 = 7.8. Without the bars the top would be −39 and the “distance” −7.8.
A line given as y = mx + c. Find the distance from (4, 1) to y = 2x + 3. Move everything to one side first: 2x − y + 3 = 0, so a = 2, b = −1 and the constant term is 3. Then d = |2 · 4 − 1 + 3| / √(4 + 1) = 10 / √5 = 2√5 ≈ 4.47. (Swedish books write the same line y = kx + m; the rewriting is identical.)
A line parallel to an axis. The line x = 4 is x − 4 = 0, so a = 1, b = 0, c = −4. From (9, 3) the distance is |9 − 4| / √1 = 5, which is the horizontal gap and nothing else.
Getting a, b and c from the line you were given
| The line is written | a | b | c |
|---|---|---|---|
| ax + by + c = 0 | a | b | c |
| ax + by = e | a | b | −e |
| y = mx + c | m | −1 | c |
| x = p | 1 | 0 | −p |
| y = q | 0 | 1 | −q |
The signs are the part to check, because the formula only works with everything on one side of the equals sign and a zero on the other.
Common mistakes
- Leaving out the absolute value. The result is negative for every point on one side of the line, which is not a distance.
- Not moving everything to one side. For y = 2x + 3 and the point (4, 1), reading b as +1 gives |8 + 1 + 3| / √5 ≈ 5.37 instead of 4.47.
- Taking c with the wrong sign. For 3x + 4y = 10 the constant term is −10. Using +10 with the point (5, 5) gives 45 / 5 = 9 instead of 5.
- Dividing by a + b. The bottom is √(a² + b²), the length of (a, b). For a = 3, b = 4 that is 5, and not 7.
- Putting the wrong numbers in for x and y. Only the point’s coordinates go into ax₀ + by₀ + c. The line’s own x and y stay out of the calculation.
Where to go next
The distance between two points is the same idea for a point and a point, and it can be used to check an answer here: find the foot of the perpendicular, then measure. The equation of a line page covers y = mx + c, and the perpendicular lines page explains why (a, b) points at right angles to the line. The absolute value is what the bars mean.
Common questions
How do I use it to test whether a point is on a line?
Put the point into ax + by + c. If the result is 0, the distance is 0 and the point is on the line.
How do I find the distance between two parallel lines?
Pick any point on one line and find its distance to the other. For two parallel lines, every point on
the first line is the same distance from the second.
Why is the answer often a surd?
The bottom is √(a² + b²), which is a whole number only when (a, b) is part of a Pythagorean triple such as
(3, 4) or (5, 12). Otherwise the distance is left as a fraction with a root, or rounded.
Does it work in three dimensions?
The same idea gives the distance from a point to a plane, ax + by + cz + d = 0, as
|ax₀ + by₀ + cz₀ + d| / √(a² + b² + c²). For a point and a line in space it does not apply as it stands.

