Math

Line equation from two points calculator

Settings
Reset
Share
Save
Embed
Report a bug

Share calculator

Add our free calculator to your website

Source

Please enter a valid URL. Only HTTPS URLs are supported.

Styling

Input border focus color, switchbox checked color, select item hover color etc.

Advanced

Please agree to the Terms of Use.

Preview

Save calculator

Calculator Settings

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Share calculator

What is a line equation from two points?

Any two distinct points that are not stacked vertically determine exactly one straight line. This calculator takes the coordinates of those two points, (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), and returns the line’s equation in slope-intercept form:

y=mx+by = mx + b

where mm is the slope (how steep the line is) and bb is the y-intercept (where the line crosses the vertical axis). The calculator reports the slope, the y-intercept, and the assembled equation.

How does it work?

The calculation happens in two steps.

Step 1 — the slope. The slope is the ratio of the vertical change to the horizontal change between the two points:

m=y2y1x2x1m = \frac{y_2 - y_1}{x_2 - x_1}

Step 2 — the y-intercept. Once the slope is known, substitute either point back into y=mx+by = mx + b and solve for bb:

b=y1mx1b = y_1 - m \, x_1

With mm and bb in hand, the equation is simply y=mx+by = mx + b.

Worked examples

Example 1: a line through the origin

For the points (0,0)(0, 0) and (2,4)(2, 4):

m=4020=2,b=02×0=0m = \frac{4 - 0}{2 - 0} = 2, \qquad b = 0 - 2 \times 0 = 0

The equation is y=2xy = 2x. Because the y-intercept is zero, the line passes through the origin.

Example 2: a positive slope with a negative intercept

For the points (1,1)(1, 1) and (3,7)(3, 7):

m=7131=62=3,b=13×1=2m = \frac{7 - 1}{3 - 1} = \frac{6}{2} = 3, \qquad b = 1 - 3 \times 1 = -2

The equation is y=3x2y = 3x - 2. The line crosses the y-axis two units below the origin.

Example 3: a horizontal line

For the points (1,2)(1, 2) and (5,2)(5, 2):

m=2251=0,b=20×1=2m = \frac{2 - 2}{5 - 1} = 0, \qquad b = 2 - 0 \times 1 = 2

The equation is y=0x+2y = 0x + 2, more simply written y=2y = 2. A zero slope means the line is flat.

What about vertical lines?

If the two points share the same x-coordinate (x1=x2x_1 = x_2), the run x2x1x_2 - x_1 is zero and the slope is undefined — you cannot divide by zero. Such a line is vertical and its equation is x=x1x = x_1, which cannot be written in the form y=mx+by = mx + b. In this case the calculator leaves the slope, y-intercept, and equation empty.

Notes

  • The slope alone tells you the direction of the line; pair this tool with the slope calculator if that is all you need.
  • The order of the two points does not matter. Swapping them negates both the numerator and denominator of the slope, leaving mm unchanged, and the y-intercept comes out the same.
  • The midpoint calculator finds the point halfway between the two coordinates, which always lies on this same line.

FAQ

What is the equation of the line through (1,1) and (3,7)?

The slope is 33 and the y-intercept is 2-2, so the equation is y=3x2y = 3x - 2.

How do I find the y-intercept from two points?

First compute the slope mm, then plug one point into b=y1mx1b = y_1 - m x_1. For (1,1)(1,1) with m=3m = 3, that gives b=13=2b = 1 - 3 = -2.

Why is there no equation for two vertical points?

When both points have the same x-coordinate the line is vertical, its slope is undefined, and it cannot be expressed as y=mx+by = mx + b. Its equation is x=x1x = x_1 instead.

Report a bug

This field is required.