Math

Equation of a line from two points

Give two points and this equation of a line calculator finds the line through them in every common form: slope-intercept y = mx + b, point-slope, standard form Ax + By = C and two-point form. It keeps slopes as exact fractions, handles vertical and horizontal lines, and adds the x- and y-intercepts, the midpoint of the two points and the distance between them.

Runs in your browser. Nothing you type is sent to us.

Equation of the line

y = (1/2)x + 2

Slope m = 1/2, y-intercept b = 2

Slope (m)
1/2 ≈ 0.5
y-intercept
(0, 2)
x-intercept
(−4, 0)
Standard form (Ax + By = C)
x − 2y = −4
Point-slope form
y − 1 = (1/2)(x + 2)
Two-point form
(y − 1) ÷ 3 = (x + 2) ÷ 6
Midpoint
(1, 5/2)
Distance between the points
6.708204

Key facts

  • Slope m = (y₂ − y₁) ÷ (x₂ − x₁), then b = y₁ − m x₁.
  • Through (−2, 1) and (4, 4): m = 3/6 = 1/2 and b = 1 + 1 = 2, so y = (1/2)x + 2.
  • Standard form: x − 2y = −4. Point-slope form: y − 1 = (1/2)(x + 2).
  • If x₁ = x₂ the line is vertical (x = constant) and has no slope-intercept form.
  • If y₁ = y₂ the line is horizontal (y = constant) with slope 0.

How to find the equation of a line from two points

  1. Slope: m = (y₂ − y₁) ÷ (x₂ − x₁).
  2. Intercept: substitute one point into y = mx + b and solve: b = y₁ − m x₁.
  3. Write the equation: y = mx + b.
  4. Check with the other point.

How to use the equation of a line calculator

  1. Enter x₁, y₁ and x₂, y₂. Decimals and negatives are fine.
  2. Read the equation in slope-intercept form, then the slope, intercepts, standard form, point-slope form and two-point form.
  3. The midpoint and distance between the points are included for convenience.

Worked examples: equations of lines

Example 1: the default

(−2, 1) and (4, 4). m = (4 − 1) ÷ (4 − (−2)) = 3/6 = 1/2. b = 1 − (1/2)(−2) = 2. y = (1/2)x + 2. Check: (1/2)(4) + 2 = 4 ✓.

Example 2: a negative slope

(1, 7) and (3, 1). m = −6/2 = −3, b = 7 + 3 = 10. y = −3x + 10.

Example 3: a vertical line

(3, 1) and (3, 5). The x-values are equal, so the slope is undefined and the line is x = 3.

Example 4: a horizontal line

(1, 5) and (4, 5). m = 0, so the line is y = 5.

Example 5: a real-world line

A taxi charges $11 for a 4 km ride and $18.50 for a 9 km ride. m = 7.50/5 = 1.50 per km, b = 11 − 6 = 5. Cost = 1.5 × km + 5: a $5 flag fall plus $1.50 per km.

Forms of a line

FormEquationGood for
Slope-intercepty = mx + bGraphing, reading slope and intercept
Point-slopey − y₁ = m(x − x₁)Writing a line from one point and a slope
StandardAx + By = CSystems of equations, integer coefficients
Two-point(y − y₁)/(y₂ − y₁) = (x − x₁)/(x₂ − x₁)Writing a line straight from two points

All four describe the same line. The calculator gives standard form with integer coefficients and a positive A.

Intercepts

The y-intercept is (0, b). The x-intercept is where y = 0: x = −b/m, which for Example 1 is (−4, 0). A horizontal line other than y = 0 never meets the x-axis; a vertical line other than x = 0 never meets the y-axis.

Parallel and perpendicular lines

Parallel lines have equal slopes. Perpendicular lines have slopes whose product is −1, so a line perpendicular to y = (1/2)x + 2 has slope −2. The perpendicular bisector of two points passes through their midpoint with that negative reciprocal slope.

Mistakes to avoid with equations of lines

  • Subtracting coordinates in different orders in the numerator and denominator.
  • Dividing by zero when x₁ = x₂ instead of recognising a vertical line.
  • Losing a sign when computing b = y₁ − m x₁ with negative values.

Two points determine a line

"A straight line can be drawn from any point to any point" is the first postulate of Euclid’s *Elements*, written around 300 BCE, and it is the reason two points are enough to fix a line. In coordinates, the slope is the change in y divided by the change in x, and either point then gives the equation. The two-point form, (y − y₁) ÷ (y₂ − y₁) = (x − x₁) ÷ (x₂ − x₁), says the same thing without computing the slope first.

Finding a line through two points is behind many everyday calculations. Linear interpolation estimates values between table entries; calibrating a thermometer or sensor from two reference points (such as the freezing and boiling points of water) is a two-point line, which is how the Fahrenheit and Celsius scales are related by F = 1.8C + 32; and converting between currencies or units with a fixed offset uses the same idea. In computer graphics, Bresenham’s line algorithm (1962), developed by Jack Bresenham at IBM, draws the line between two pixels efficiently. In US schools, Common Core standard 8.F.B.4 asks students to find a linear function from two (x, y) values. Once the slope is known, plug either point into the point-slope form, then set x = 0 to find the y-intercept. For values between the points, use the linear interpolation calculator; for the distance between them, the distance formula calculator; and for their midpoint, the midpoint calculator.

Related: the slope calculator, the point-slope form calculator, the distance formula calculator and the midpoint calculator.

How this calculator works

  • Builds the line from a slope and a point, from two points, or from standard form Ax + By = C.
  • Slope m = (y₂ − y₁) ÷ (x₂ − x₁); y-intercept b = y₁ − m × x₁.
  • Shows slope-intercept form y = mx + b, point-slope form, standard form, the intercepts, the perpendicular slope and the angle of the line.
  • Vertical lines (equal x values) are reported as x = c, since their slope is undefined.

Frequently asked questions

How do you find the equation of a line from two points?

Find the slope m = (y₂ − y₁)/(x₂ − x₁), then b = y₁ − m x₁, and write y = mx + b.

What is the equation of the line through (−2, 1) and (4, 4)?

y = (1/2)x + 2.

What if the two points have the same x-coordinate?

The line is vertical, x = that value, and its slope is undefined.

What if the two points have the same y-coordinate?

The line is horizontal, y = that value, with slope 0.

What is standard form of a line?

Ax + By = C, usually with integers and A positive. For y = (1/2)x + 2 it is x − 2y = −4.

What is the two-point form?

(y − y₁)/(y₂ − y₁) = (x − x₁)/(x₂ − x₁), written directly from the two points.

Does it matter which point I call the first?

No. Swapping the points gives the same slope and the same line.

How do I find a perpendicular line?

Use the negative reciprocal of the slope, then a point it must pass through.

Sources

  1. OpenStax: College Algebra 2e, section 2.2 Linear Equations in One Variable
  2. Math is Fun: Equation of a straight line
  3. Wolfram MathWorld: Line

Updated November 25, 2026. Formulas checked against published sources and worked examples.

Cite this page: CalcRoster. "Equation of a line from two points." calcroster.com/equation-of-a-line-calculator/. Updated November 25, 2026.

Results are estimates for general information. They are not financial, medical or legal advice. Check important decisions with a qualified professional.