Guide

Finding the equation of a straight line from two points

By Viktor Lassen5 min readUpdated 3 September 2026

Given two points on a line, the two-point formula gives you the gradient m, and putting one point back in gives you c. Here is the whole method, and why the formula looks the way it does.

Often we need the gradient of a linear function, and we are not told what it is. There are several ways to find it, and it depends entirely on what information we have, but typically we have been given two points. This guide shows the formula that gives the gradient mm from two points, why it works, and how to find cc afterwards, so we end up with the whole equation of the line.

When do I use this?

Whenever a question gives you two points on a straight line, as coordinates or as points you can read off a graph, and asks for the equation of the line. The same method also covers the case where you are given one point and the gradient: then you skip straight to the second half, finding cc.

The two-point formula

If we have two points

(x1,y1)Β andΒ (x2,y2)(x_1, y_1) \text{ and } (x_2, y_2)

that lie on the line, we can find the gradient with the formula, which funnily enough is called the two-point formula:

m=y2βˆ’y1x2βˆ’x1m = \frac{y_2 - y_1}{x_2 - x_1}

The formula says that we find the difference between the two points' yy-values, and divide it by the difference between the xx-values.

Worked example: the line through (2, 4) and (5, 8)

The line through (2, 4) and (5, 8): we go 4 up the y-axis while we go 3 along the x-axis

Here we can see that we have two points on the graph:

(2,4)Β andΒ (5,8)(2, 4) \text{ and } (5, 8)

Here 2 is x1x_1, 4 is y1y_1, 5 is x2x_2 and 8 is y2y_2. All we do now is put the numbers into the formula:

m=8βˆ’45βˆ’2=43β‰ˆ1.33m = \frac{8 - 4}{5 - 2} = \frac{4}{3} \approx 1.33

So we have found that with these two points, the gradient is 43\frac{4}{3}, about 1.33.

Why does the formula look like that?

Why does the formula look the way it does? After all, we want to find out how much we go up the y-axis when we go 1 along the x-axis (that is the gradient).

In the example we saw that we went 4 up the y-axis while we went 3 along the x-axis. We need to find out how much we go up when we only go 1 along. So we divide 4 by 3. See it as scaling the whole thing down: we need to know how far up we go for 1 along instead of 3. We can do that by dividing by 3, because 3 divided by 3 is 1. And of course that means we have to divide 4 by 3 as well.

The same triangle scaled down: 1 along the x-axis and 4/3 up the y-axis

43β‰ˆ1.33\frac{4}{3} \approx 1.33

What we did was really just to scale this triangle down, so that we go 1 along the x-axis instead of 3.

To find the gradient, then, we actually took the difference between the two yy-values, which in our example was 4, and divided it by the difference between the xx-values, which in our example was 3. That is to say, to find the gradient we divide the difference in the yy-values by the difference in the xx-values:

m=y2βˆ’y1x2βˆ’x1m = \frac{y_2 - y_1}{x_2 - x_1}

That is how the formula comes about.

Sometimes you might see the formula written as

m=Ξ”yΞ”xm = \frac{\Delta y}{\Delta x}

But this delta sign, Ξ”\Delta, is just a sign we use to show a difference between two things. Here it is the difference in yy divided by the difference in xx.

Finding c

All we need to do to find cc is to get it on its own in the equation of a linear function:

y=mx+cy = mx + c

We subtract mxmx from both sides, and get:

yβˆ’mx=cy - mx = c

So to find cc we need to know the gradient and an (x,y)(x, y), which is any point that lies on the graph. If we take the example from before, where we have the gradient and two points, we can find cc. Here we actually have two points, which is fine, but we can easily make do with just one. We choose ourselves which point we use. I'll take the first point. Then we simply put it into the formula we have just made:

c=yβˆ’mxc = y - mx

c=4βˆ’43Γ—2=43c = 4 - \frac{4}{3} \times 2 = \frac{4}{3}

We have now found cc and can actually write down the whole equation of the line:

y=mx+cy = mx + c

y=43x+43y = \frac{4}{3}x + \frac{4}{3}

or, with decimals, roughly y=1.33x+1.33y = 1.33x + 1.33.

One point and a gradient

If a question gives you a gradient and one point instead of two points, you already have mm, so you go straight to c=yβˆ’mxc = y - mx. Had we been told m=43m = \frac{4}{3} and the point (2,4)(2, 4), we would do exactly the last step above: c=4βˆ’43Γ—2=43c = 4 - \frac{4}{3} \times 2 = \frac{4}{3}, and the line is y=43x+43y = \frac{4}{3}x + \frac{4}{3} again.

Common mistakes

  • "The gradient is just how far up the line went." No, it is how far up for exactly 1 along. Between (2,4)(2, 4) and (5,8)(5, 8) the line went 4 up, but over 3 along, so the gradient is 43\frac{4}{3}, not 4. The division by the xx-difference is the whole point of the formula.
  • "I need both points to find c." One is enough. Both points lie on the line, so either works in c=yβˆ’mxc = y - mx. You choose.
  • "Which point I use for c changes the answer." It doesn't. Both points lie on the line, so they give the same cc. We choose ourselves which one to use.

Frequently asked questions

Read next

Want to get good at maths?

Mathara explains every topic step by step with videos, exercises and personal feedback.

πŸ‘‰ Get started for free