Distance From a Point to a Line Calculator

Find the shortest distance from a point to a line given as Ax + By + C = 0 or y = mx + b, plus the closest point on the line. Free, with steps.

This calculator finds the shortest distance from a point to a line. Enter the point and the line, written either as Ax + By + C = 0 or as y = mx + b, and it returns the distance, the closest point on the line and the steps.

The shortest distance is always measured along the perpendicular from the point to the line, so the closest point is where that perpendicular meets the line.

This calculator needs JavaScript. Please enable it in your browser.

How the distance from a point to a line is calculated

The formula

For a point (x0, y0) and a line Ax + By + C = 0:

d = |Ax0 + By0 + C| ÷ √(A² + B²)

The top is the absolute value of the line’s expression evaluated at the point. The bottom is the length of the line’s normal vector (A, B).

Starting from y = mx + b

Rewrite the line as −mx + y − b = 0, so A = −m, B = 1 and C = −b, then use the same formula. The calculator does this when you choose the y = mx + b option.

Finding the closest point

Move from the point along the normal direction by the amount that brings you to the line.

foot = (x0 − A·s ÷ (A² + B²), y0 − B·s ÷ (A² + B²)), where s = Ax0 + By0 + C

Worked examples

Example 1: general form

Find the distance from (5, 6) to 3x + 4y − 12 = 0. Here s = 3 × 5 + 4 × 6 − 12 = 27 and √(3² + 4²) = 5.

d = 27 ÷ 5 = 5.4

The closest point on the line is (1.76, 1.68), and 3 × 1.76 + 4 × 1.68 = 12, so it lies on the line.

Example 2: slope-intercept form

Find the distance from (2, −1) to y = 0.5x + 3. Rewriting gives −0.5x + y − 3 = 0, so s = −0.5 × 2 + (−1) − 3 = −5 and √(0.25 + 1) ≈ 1.1180.

d = 5 ÷ 1.1180 ≈ 4.4721

Example 3: a horizontal line

For y = 5 and the point (3, 9), the distance is simply 9 − 5 = 4. The formula agrees: A = 0, B = 1, C = −5, so d = absolute value of (9 − 5) ÷ 1 = 4.

Frequently asked questions

What is the formula for the distance from a point to a line?

d = absolute value of (Ax0 + By0 + C) divided by the square root of (A² + B²), for a line Ax + By + C = 0 and a point (x0, y0).

How do I use a line written as y = mx + b?

Choose the y = mx + b option and enter m and b. The calculator rewrites the line as −mx + y − b = 0 before applying the formula.

What if the point is on the line?

The distance is zero, because Ax0 + By0 + C equals zero for any point on the line.

Why is the shortest distance along the perpendicular?

Any other path from the point to the line is the hypotenuse of a right triangle whose other side lies along the line, so it is longer than the perpendicular.

Does it work for vertical and horizontal lines?

Yes. Use the Ax + By + C = 0 form: a vertical line x = 4 is A = 1, B = 0, C = −4, and a horizontal line y = 5 is A = 0, B = 1, C = −5.