Finding the equation of a line through two points is one of the fundamental problems in analytic geometry. This situation comes up in a huge number of exercises and problems, and it forms the basis for the study of parallel and perpendicular lines, families of lines, the distance from a point to a line, and more.
In this article, we will look at two general methods for finding the equation of a line through two points, with clear explanations, step-by-step worked examples, and the special cases worth knowing.
The Problem
Given two distinct points in the Cartesian plane:
the goal is to find the equation of the line that passes through both points.
Exactly one line passes through any two distinct points.
Methods for Finding the Equation of a Line Through Two Points
There are two common methods for finding the equation of a line through two points.
The first method consists of first calculating the slope of the line from the coordinates of points A and B, and then using the point-slope equation with either point A or point B. The second method uses the two-point form, which allows us to obtain the equation of the line directly from the coordinates of points A and B.
Both methods are entirely equivalent and must lead to the same result when applied correctly, as we will demonstrate below. Let’s look at them one by one!
First method: passage through a point with a known slope
Essential theory recap: the slope.
The slope of the line passing through the points \(A(x_1,y_1)\) and \(B(x_2,y_2)\) is given by:
It represents the incline of the line with respect to the \(x\)-axis.
The formula for calculating \(m\) is valid only if \(x_1\) and \(x_2\) are different from each other!
The procedure for finding the equation of a line through a point with a known slope consists of three steps, which we describe below:
1. Calculating the slope
We apply the formula:
\[ m = \frac{y_2 – y_1}{x_2 – x_1} \]
which represents the slope of the line passing through points \(A\) and \(B\).
2. Choosing the form of the equation
We use the point-slope equation in the form:
\[ y – y_0 = m(x – x_0) \]
This equation can also be viewed as a particular case of the family of concurrent lines through one of the two points A or B, but where the slope m is known.
3. Substituting the numerical values
We substitute the coordinates of one of the two points (either A or B, it makes no difference), obtaining the equation we are looking for.
An important detail, to avoid any confusion:
if, for example, we choose to substitute the coordinates of point A, we will have:
\[x_1=x_0\]
\[y_1=y_0\]
If instead we decide, alternatively, to substitute the coordinates of point B into the point-slope equation, we will write:
\[x_2=x_0\]
\[y_2=y_0\]
Once the value of the slope \(m\) has been substituted, it is easy to see that the equation obtained is exactly the equation we are looking for.
⚠️ Note: it is not necessary to require the line to pass through the second point, since this condition is already accounted for implicitly through the calculation of the slope \(m\).
Worked Example
Find the equation of the line passing through the points:
\[A(1,2)\]\[B(6,9)\]
Step 1: calculating the slope
\[ m = \frac{9 – 2}{6 – 1} = \frac{7}{5} \]
Step 2: point-slope form
Substituting the value of \(m\) into the point-slope equation and the coordinates of either point, for example \(A\), we obtain:
\[ y – 2 = \frac{7}{5}(x – 1) \]
Step 3: simplifying
Finally, we simplify:
\[ y – 2 = \frac{7}{5}x-\frac{7}{5} \]
\[ y = \frac{7}{5}x+\frac{3}{5} \]
Equation of the line:
\[ y = \frac{7}{5}x+\frac{3}{5} \]

Second method: two-point form of a line through two points
There is another, more direct method for immediately finding the Cartesian equation of a line through two points: specifically, we can make use of the following formulation, called the two-point form:
\[\frac{y-y_{1}}{y_{2}-y_{1}}=\frac{x-x_{1}}{x_2-x_1}\]
If we try applying this equation to the exercise worked out in the previous section, this other method must also produce the same equation of the line as the final result.
Let’s verify whether this is true.
Points: \(A(1,2)\) \(B(6,9)\)
We substitute the numerical values of the coordinates into the equation in two-point form, obtaining:
\[\frac{y-2}{9-2}=\frac{x-1}{6-1}\]
Simplifying, we get:
\[\frac{y-2}{7}=\frac{x-1}{5}\]
from which
\[y-2=\frac{7}{5}(x-1)\]
which is exactly the equation obtained with the first method (before simplification).
Now it is enough to simplify (as in Step 3 of the first method) to obtain exactly the same final result:
\[ y = \frac{7}{5}x+\frac{3}{5} \]
Checking the Result
We substitute the coordinates of the points into the equation we found:
- For \(A(1,2)\): \(2 = 7/5 \cdot 1+3/5\) ✓
- For \(B(6,9)\): \(9 = 7/5 \cdot 6+3/5\) ✓
The check is satisfied.
This method is one of several fundamental techniques covered in the complete guide on the line in analytic geometry.
Special Case: Vertical Line
If \(x_1 = x_2\), the slope is undefined.
In this case the line is vertical, and its equation is:
\[ x = x_1 \]
Example
If the points are:
\[A(3,1)\;\;\;B(3,5)\]
the equation of the line passing through these points is:
\[ x = 3 \]
Special Case: Horizontal Line
If \(y_1 = y_2\), the slope is zero:
\[ m = 0 \]
In that case, the equation of the line is:
\[ y = y_1 \]
Common Mistakes to Avoid
- Swapping the coordinates in the slope formula
- Using formulas that don’t apply when \(x_1 = x_2\)
- Forgetting to simplify the final equation
- Using coincident points
- Making calculation errors during simplification
Practice Problems with Solutions
- Find the equation of the line passing through the points A(0,1) and B(2,5). [Solution: y=2x+1]
- Find the equation of the line passing through the points A(-1,3) and B(2,3). [Solution: y=3]
- Find the equation of the line passing through the points A(4,-2) and B(4,6). [Solution: x=4]
Conclusion
Knowing how to find the equation of a line through two points is an essential step in the study of analytic geometry. The methods presented above are used in a great many contexts across mathematics, physics, and applied mathematics, and they form the basis for solving more complex geometric and analytic problems.
Final Test
Before moving on, a short test offers the chance to check how well the two methods covered in this article have been absorbed. The ten questions below mix conceptual points and short calculations, moving from the slope formula through both methods and the special cases of vertical and horizontal lines. Each question allows one attempt, with feedback shown immediately after answering.
Cite this resource
"No shortcuts went into this one — just careful writing and checking. If it helped you, consider sharing it or citing it as a source."
Citation
HTML link to copy