Coordinate Geometry

Finding the equation of a straight line from two points

By Mr Gan · O-Level E Maths · Updated August 2026 · 7 min read

To find the equation of a straight line through two points on the Cartesian plane, first find the gradient using m = (y₂ − y₁) ÷ (x₂ − x₁). Then write y = mx + c and substitute the coordinates of either point to solve for c. Write out the final equation with both values filled in. This same gradient-then-substitute method also gives you the equation of any line parallel to a known one.

Why this trips students up

The gradient formula only breaks down when students mix up the order of subtraction: taking y₁ − y₂ on top but x₂ − x₁ on the bottom, or subtracting the x-coordinates and y-coordinates from different points. The order does not matter as long as it is the same on top and bottom. What matters is consistency.

The second common gap is stopping after finding m. The gradient alone is not the equation of the line: it still needs c, the y-intercept, which comes from substituting a known point back into y = mx + c.

The method

Step 1

Label the points (x₁, y₁) and (x₂, y₂)

Step 2

Find m = (y₂ − y₁) ÷ (x₂ − x₁)

Step 3

Sub one point into y = mx + c to find c

Step 4

Write the equation with m and c filled in

A quick sanity check before the algebra: if a line rises as x increases, it is "uphill" and m is positive. If it falls as x increases, it is "downhill" and m is negative. Checking this against your calculated m catches sign errors immediately.

Watch the whole method in about a minute.

Worked example 1: equation through two points

Find the equation of the straight line passing through (1, 3) and (4, 9).

Solution

1
Let (x₁, y₁) = (1, 3) and (x₂, y₂) = (4, 9).
2
Find the gradient:
m = (9 − 3) ÷ (4 − 1) = 6 ÷ 3 = 2
3
Write y = 2x + c and substitute the point (1, 3):
3 = 2(1) + c, so c = 3 − 2 = 1.
4
The equation is y = 2x + 1.

Quick check: substitute the other point, (4, 9), into your equation: y = 2(4) + 1 = 9. It matches, so the equation is correct. Always check with the point you did not use to find c.

Worked example 2: parallel to a given line

Find the equation of the line parallel to y = 3x − 2 that passes through (2, 5).

Solution

1
Parallel lines have the same gradient, so m = 3, taken directly from y = 3x − 2.
2
Write y = 3x + c and substitute the point (2, 5):
5 = 3(2) + c, so c = 5 − 6 = −1.
3
The equation is y = 3x − 1.

The step students get wrong

In the gradient formula, the order of subtraction on top and bottom must match. If you take y₂ − y₁ on top, you must take x₂ − x₁ on the bottom, using the same two points in the same order. Mixing the order (for example y₁ − y₂ over x₂ − x₁) flips the sign of m and gives the wrong line entirely. Label your points clearly before you start and stick to that labelling all the way through.

Horizontal and vertical lines

Two special cases do not fit the standard y = mx + c form the same way, and both come up often in exams.

A horizontal line has the same y-value at every point, so its gradient is 0 and its equation is simply y = k for some constant k. For example, the line through (1, 4) and (6, 4) is y = 4, the same constant relationship you read directly off a conversion graph.

A vertical line has the same x-value at every point. Its gradient is undefined (the denominator in the gradient formula becomes zero), and its equation is x = k. For example, the line through (2, 0) and (2, 5) is x = 2. Never try to force a vertical line into y = mx + c: it has no such form.


Frequently asked questions

What if the two points give a gradient that is a fraction?

That is completely normal and expected. Keep the fraction unsimplified until the end if it helps avoid rounding errors, and substitute it into y = mx + c exactly as it is. The final equation can keep the fractional gradient.

Does it matter which of the two points I substitute to find c?

No. Either point gives the same value of c, because both points lie on the same line. Pick whichever point has smaller or simpler numbers to reduce arithmetic slips.

How do I know two lines are parallel just from their equations?

Compare the coefficient of x once both equations are written in y = mx + c form. If the gradients m are equal, the lines are parallel. The c values (the y-intercepts) can be different, and usually are.

Why is the gradient of a vertical line undefined rather than zero?

The gradient formula divides by (x₂ − x₁). For a vertical line, every point shares the same x-coordinate, so x₂ − x₁ = 0, and division by zero is undefined. A gradient of zero belongs to a horizontal line, not a vertical one: the two are easy to swap by mistake.

This same coordinate geometry toolkit shows up again in two other places worth knowing. The distance and midpoint formula uses the same two points to work out how far apart they are and where the line between them crosses its middle, and both build on the coordinate ideas here. If a question instead gives you a sequence of points rather than a line, finding the nth term of a sequence uses the same idea of a constant rate of change (a common difference) that the gradient m represents for a straight line.

— Mr Gan Math Tuition

Still mixing up your gradient signs?

Mr. Gan works with students who want a systematic, repeatable method for coordinate geometry, not shaky guesswork under exam pressure.

Chat with Mr. Gan