Find the slope and equation of a straight line through two points. Enter x and y for each point. The tool distinguishes ordinary, horizontal, and vertical lines, and explains why two identical points do not determine a unique line.

Use consistent coordinate units. Decimal inputs are retained as exact fractions for the slope and intercept; a separate rounded slope is labeled as an approximation.

A line through negative two comma one and four comma ten has slope three halves and y-intercept four.
The points (−2, 1) and (4, 10) give a rise of 9 and run of 6.Credit: MathBlog

Find the line through two points

Enter decimal coordinates with a decimal point, at most 12 digits in total per coordinate and 6 decimal places. No exponents or thousands separators. Coordinates must use consistent units.

Calculations run in your browser. Your entries are not sent to a MathBlog calculation service. Exact results and approximate values are labeled separately.

A worked example

Take the points \((-2,1)\) and \((4,10)\). The horizontal change is \(4-(-2)=6\), and the vertical change is \(10-1=9\). The slope is \(\frac{9}{6}=\frac{3}{2}\).

Insert the first point into \(y=mx+b\): \(1=\frac{3}{2}(-2)+b\). This gives \(b=4\), so the line is \(y=\frac{3}{2}x+4\). Its integer standard form is \(3x-2y=-8\).

Check both points. At \(x=-2\), the line gives \(y=1\). At \(x=4\), it gives \(y=10\). Checking only one point is insufficient because many lines can pass through a single point.

Vertical and horizontal cases

If the two x coordinates are equal and the y coordinates differ, the line is vertical. Its equation is \(x=\text{that shared value}\), and its slope is undefined. There is no finite m and b representation \(y=mx+b\).

If the y coordinates are equal and the x coordinates differ, the slope is zero. The line is horizontal, with equation \(y=\text{that shared }y\text{ value}\).

Two identical points give neither a unique slope nor a unique line. The tool reports that case rather than attempting to divide zero by zero.

Input and output conventions

Enter at most 12 digits in total and 6 decimal places per coordinate. Use a decimal point; commas, scientific notation, and units are not accepted in the fields. Integers and negative coordinates are valid.

The standard form uses integer coefficients without a common integer factor, with the first nonzero coefficient positive. Equivalent equations may look different because every coefficient can be multiplied by the same nonzero number.

Slope is a ratio of coordinate changes. It does not by itself state the angle of a displayed graph unless units and axis scales are appropriate. Read MathBlog’s slope reference for more examples and interpretation.

Further reading