Line Equation from Two Points Calculator

Line Equation from Two Points Calculator

Growing AI Skill PRO

Enter Calculation

Formula

y=mx+bwhere{m=y2−y1x2−x1b=y1−m·x1\begin{gathered} y = m\,x + b \\[1.5em] \text{where}\quad \left\{ \begin{aligned} m &= \dfrac{{{\text{y}_2}} - {{\text{y}_1}}}{{{\text{x}_2}} - {{\text{x}_1}}} \\ b &= {{\text{y}_1}} - m\cdot{{\text{x}_1}} \end{aligned} \right. \end{gathered}
Show calculation steps (1)
  1. Distance Between Points

    d=(x2−x1)2+(y2−y1)2d = \sqrt{\left({{\text{x}_2}} - {{\text{x}_1}}\right)^2 + \left({{\text{y}_2}} - {{\text{y}_1}}\right)^2}

    Euclidean distance between the two points

Usage stats

Advertisement

Results

Slope-Intercept Equation
y = 2x + 0
line through the two points
Slope (m) 2
Y-intercept (b) 0
Distance between points 4.472136

Report an error on this page

What this calculator does

The Line Equation from Two Points Calculator finds the straight line that passes through any two points in the coordinate plane. Enter the coordinates of point one (x₁, y₁) and point two (x₂, y₂), and the tool returns the slope, the y-intercept, the full slope-intercept equation \(y = mx + b\), and the straight-line distance between the points.

How to use it

Type the four coordinate values into the boxes and submit. The calculator first computes the slope, then uses the point-slope relationship to derive the y-intercept and produce the final equation. If the two x-values are equal, the line is vertical and is written as x = constant because its slope is undefined.

The formula explained

The slope m is the change in y divided by the change in x: \(m = (\text{y}_2 - \text{y}_1) / (\text{x}_2 - \text{x}_1)\). This measures steepness — how much y rises for each unit increase in x. Once you have m, the point-slope form \(y - \text{y}_1 = m(x - \text{x}_1)\) describes the line. Expanding it gives the slope-intercept form $$y = mx + b$$ where the intercept \(b = \text{y}_1 - m\cdot\text{x}_1\) is the value of y where the line crosses the vertical axis.

Advertisement
Two points on a coordinate plane connected by a line showing rise and run
Slope is the rise over the run between the two points.

Worked example

For the points (1, 2) and (3, 6): slope $$m = \frac{6 - 2}{3 - 1} = \frac{4}{2} = 2.$$ The intercept \(b = 2 - 2\cdot1 = 0\), so the equation is \(y = 2x\). The distance between the points is $$\sqrt{(3-1)^2 + (6-2)^2} = \sqrt{4 + 16} = \sqrt{20} \approx 4.472.$$

Line crossing the y-axis showing slope and y-intercept
The line's y-intercept is where it crosses the vertical axis.

Special Cases: Slope Types at a Glance

The slope is \(m = \frac{y_2 - y_1}{x_2 - x_1}\) and the y-intercept is \(b = y_1 - m x_1\). The table shows how different point pairs behave.

Points Slope (m) y-intercept (b) Equation Line direction
(1, 2) & (3, 6) 2 (since 4 ÷ 2) 0 y = 2x Rises left to right (positive slope)
(0, 5) & (2, 1) −2 (since −4 ÷ 2) 5 y = −2x + 5 Falls left to right (negative slope)
(1, 4) & (5, 4) 0 (since 0 ÷ 4) 4 y = 4 Horizontal
(3, 1) & (3, 7) Undefined (since 6 ÷ 0) None (the line never crosses the y-axis) x = 3 Vertical
(2, 3) & (6, 6) 0.75 (3/4, since 3 ÷ 4) 1.5 (since 3 − 0.75·2) y = 0.75x + 1.5 Rises gently (positive fractional slope)

Note that a vertical line is not a function of x, so it cannot be written in slope-intercept form. It is written as x = constant.

Interpreting Your Result

  • Sign of the slope: a positive slope means the line rises from left to right, a negative slope means it falls, a slope of zero means the line is horizontal, and an undefined slope (x1 = x2) means the line is vertical.
  • Steepness: the larger the absolute value |m|, the steeper the line. A slope of −3 is steeper than a slope of 2, while a slope of 0.25 is quite shallow.
  • y-intercept: b is the value of y where the line crosses the y-axis, at x = 0. Vertical lines (other than x = 0) have no y-intercept.
  • Distance: the calculator's distance is the length of the straight segment between your two points, \(d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\). The line itself extends infinitely in both directions. For (1, 2) and (3, 6): \(d = \sqrt{2^2 + 4^2} = \sqrt{20} \approx 4.472\).
  • Parallel and perpendicular lines: parallel lines have equal slopes. Perpendicular lines have slopes that are negative reciprocals, so \(m_1 \cdot m_2 = -1\). For example, a line with slope 2 is perpendicular to any line with slope −1/2. A horizontal line is perpendicular to a vertical line.
Advertisement

Key Terms and Definitions

  • Slope (m): the rate of change of y with respect to x, \(m = \frac{y_2 - y_1}{x_2 - x_1}\).
  • y-intercept (b): the y-value where the line crosses the y-axis (x = 0).
  • Slope-intercept form: \(y = mx + b\).
  • Point-slope form: \(y - y_1 = m(x - x_1)\), using the slope and any one known point on the line.
  • Rise and run: the rise is the vertical change \(y_2 - y_1\) and the run is the horizontal change \(x_2 - x_1\). Slope = rise ÷ run.
  • Undefined slope: occurs when the run is 0, because division by zero is not defined. It describes a vertical line.
  • Vertical line: a line of the form x = c, where every point has the same x-coordinate.
  • Horizontal line: a line of the form y = c, with slope 0.
  • Distance between two points: the straight-line (Euclidean) length of the segment joining them, given by the distance formula \(d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\), which comes from the Pythagorean theorem.

FAQ

What if both points have the same x? The line is vertical, slope is undefined, and the equation is written \(x = \text{x}_1\).

What if both points have the same y? The line is horizontal with slope 0, giving \(y = \text{y}_1\).

Can I use negative or decimal coordinates? Yes — any real numbers are accepted, including negatives and decimals.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators