Skip to content
Find the Equation of a Line

Find the Equation of a Line

By the end of this section, you will be able to: find an equation of the line given the slope and yy-intercept, find an equation of the line given the slope and a point, find an equation of the line given two points, find an equation of a line parallel to a given line, and find an equation of a line perpendicular to a given line.

The physical sciences, social sciences, and the business world are full of situations that can be modeled with linear equations relating two variables. If data appears to form a straight line when graphed, an equation of that line can be used to predict the value of one variable based on the value of the other. To create a mathematical model of a linear relation between two variables, we must be able to find the equation of the line. In this section we look at several ways to write the equation of a line — the method we use is determined by what information we are given.

Find an equation of the line given the slope and yy-intercept

If we already know the slope and yy-intercept of a line, we can find its equation by substituting the values directly into the slope-intercept form, y=mx+by = mx + b.

Example. Find an equation of a line with slope 7-7 and yy-intercept (0,1)(0, -1).

We substitute m=7m = -7 and b=1b = -1 into y=mx+by = mx + b:

y=7x+(1)=7x1y = -7x + (-1) = -7x - 1

Example. Find the equation of the line shown, whose yy-intercept is (0,4)(0, -4) and which also passes through (3,2)(3, -2).

We find the slope by counting the rise and run between the two points: m=23m = \tfrac{2}{3}. Substituting m=23m = \tfrac{2}{3} and b=4b = -4 into y=mx+by = mx + b:

y=23x4y = \frac{2}{3}x - 4

Find an equation of a line with slope 25\tfrac{2}{5} and y-intercept (0,4)(0, 4).

Find an equation of a line with slope -1 and y-intercept (0, -3).

Find an equation of the line given the slope and a point

The slope-intercept form works well when we know the slope and yy-intercept. But what if we know the slope and some other point that isn’t the yy-intercept? We can derive another form of the equation by starting with the slope formula for a line through a specific point (x1,y1)(x_1, y_1) and some other point (x,y)(x, y):

m=yy1xx1m = \frac{y - y_1}{x - x_1}

Multiplying both sides by xx1x - x_1 and simplifying gives yy1=m(xx1)y - y_1 = m(x - x_1).

Point-slope form of an equation of a line. The point-slope form of an equation of a line with slope mm and containing the point (x1,y1)(x_1, y_1) is

yy1=m(xx1)y - y_1 = m(x - x_1)

We can use the point-slope form to find an equation of a line when we are given the slope and one point, then rewrite the equation in slope-intercept form.

Find an equation of a line given the slope and a point.

  1. Identify the slope.
  2. Identify the point.
  3. Substitute the values into the point-slope form, yy1=m(xx1)y - y_1 = m(x - x_1).
  4. Write the equation in slope-intercept form.

Example. Find an equation of a line with slope m=25m = \tfrac{2}{5} that contains the point (10,3)(10, 3). Write the equation in slope-intercept form.

Substituting m=25m = \tfrac{2}{5} and (x1,y1)=(10,3)(x_1, y_1) = (10, 3) into the point-slope form:

yy1=m(xx1)y3=25(x10)y3=25x4y=25x1 \begin{align} y - y_1 &= m(x - x_1) \\ y - 3 &= \frac{2}{5}(x - 10) \\ y - 3 &= \frac{2}{5}x - 4 \\ y &= \frac{2}{5}x - 1 \end{align}

Example. Find an equation of a horizontal line that contains the point (1,2)(-1, 2). Write the equation in slope-intercept form.

Every horizontal line has slope 00. Substituting m=0m = 0 and (x1,y1)=(1,2)(x_1, y_1) = (-1, 2):

yy1=m(xx1)y2=0(x(1))y2=0y=2 \begin{align} y - y_1 &= m(x - x_1) \\ y - 2 &= 0(x - (-1)) \\ y - 2 &= 0 \\ y &= 2 \end{align}

This is the equation of the horizontal line y=2y = 2.

Find an equation of a line with slope m=13m = -\tfrac{1}{3} that contains the point (6,4)(6, -4). Write the equation in slope-intercept form.

Find an equation of the line given two points

When real-world data is collected, a linear model can often be created from just two data points. We have two options so far for finding an equation of a line: slope-intercept or point-slope. Since we will know two points rather than the slope directly, it makes more sense to first find the slope from the two points, then use the point-slope form.

Find an equation of a line given two points.

  1. Find the slope using the given points.
  2. Choose one point.
  3. Substitute the values into the point-slope form, yy1=m(xx1)y - y_1 = m(x - x_1).
  4. Write the equation in slope-intercept form.

Example. Find an equation of a line that contains the points (5,4)(5, 4) and (3,6)(3, 6). Write the equation in slope-intercept form.

First we find the slope:

m=y2y1x2x1=6435=22=1m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{6 - 4}{3 - 5} = \frac{2}{-2} = -1

Choosing the point (5,4)(5, 4) and substituting into the point-slope form:

yy1=m(xx1)y4=1(x5)y4=x+5y=x+9 \begin{align} y - y_1 &= m(x - x_1) \\ y - 4 &= -1(x - 5) \\ y - 4 &= -x + 5 \\ y &= -x + 9 \end{align}

Using the other point, (3,6)(3, 6), gives the same equation.

Example. Find an equation of a line that contains the points (2,4)(-2, 4) and (2,3)(-2, -3). Write the equation in slope-intercept form.

Finding the slope:

m=y2y1x2x1=342(2)=70m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{-3 - 4}{-2 - (-2)} = \frac{-7}{0}

The slope is undefined, telling us this is a vertical line. Both points have xx-coordinate 2-2, so the equation of the line is x=2x = -2. Since there is no yy, we cannot write it in slope-intercept form.

To write an equation of a line

If given:Use:Form:
Slope and yy-interceptslope-intercepty=mx+by = mx + b
Slope and a pointpoint-slopeyy1=m(xx1)y - y_1 = m(x - x_1)
Two pointspoint-slopeyy1=m(xx1)y - y_1 = m(x - x_1)

Find an equation of a line that contains the points (3, 1) and (5, 6). Write the equation in slope-intercept form.

Find an equation of a line parallel to a given line

Suppose we need to find an equation of a line that passes through a specific point and is parallel to a given line. Since parallel lines have the same slope, we already have the slope we need — we just combine it with the given point using the point-slope form. We write mm_\parallel for the slope of a line parallel to a line with slope mm.

Find an equation of a line parallel to a given line.

  1. Find the slope of the given line.
  2. Find the slope of the parallel line — parallel lines have the same slope.
  3. Identify the point.
  4. Substitute the values into the point-slope form, yy1=m(xx1)y - y_1 = m(x - x_1).
  5. Write the equation in slope-intercept form.

Example. Find an equation of a line parallel to y=2x3y = 2x - 3 that contains the point (2,1)(-2, 1). Write the equation in slope-intercept form.

The given line is in slope-intercept form with m=2m = 2. Since parallel lines have the same slope, m=2m_\parallel = 2. Substituting m=2m = 2 and (x1,y1)=(2,1)(x_1, y_1) = (-2, 1) into the point-slope form:

yy1=m(xx1)y1=2(x(2))y1=2x+4y=2x+5 \begin{align} y - y_1 &= m(x - x_1) \\ y - 1 &= 2(x - (-2)) \\ y - 1 &= 2x + 4 \\ y &= 2x + 5 \end{align}

Find an equation of a line parallel to the line y=3x+1y = 3x + 1 that contains the point (4,2)(4, 2). Write the equation in slope-intercept form.

Find an equation of a line perpendicular to a given line

Now consider finding a line through a specific point that is perpendicular to a given line. Perpendicular lines have slopes that are negative reciprocals of each other, so we again already have the slope we need. We write mm_\perp for the slope of a line perpendicular to a line with slope mm.

Find an equation of a line perpendicular to a given line.

  1. Find the slope of the given line.
  2. Find the slope of the perpendicular line — perpendicular slopes are negative reciprocals of each other.
  3. Identify the point.
  4. Substitute the values into the point-slope form, yy1=m(xx1)y - y_1 = m(x - x_1).
  5. Write the equation in slope-intercept form.

Example. Find an equation of a line perpendicular to y=2x3y = 2x - 3 that contains the point (2,1)(-2, 1). Write the equation in slope-intercept form.

The given line has m=2m = 2, so the perpendicular slope is the negative reciprocal, m=12m_\perp = -\tfrac{1}{2}. Substituting m=12m = -\tfrac{1}{2} and (x1,y1)=(2,1)(x_1, y_1) = (-2, 1):

yy1=m(xx1)y1=12(x(2))y1=12x1y=12x \begin{align} y - y_1 &= m(x - x_1) \\ y - 1 &= -\frac{1}{2}(x - (-2)) \\ y - 1 &= -\frac{1}{2}x - 1 \\ y &= -\frac{1}{2}x \end{align}

Example. Find an equation of a line perpendicular to x=5x = 5 that contains the point (3,2)(3, -2). Write the equation in slope-intercept form.

The line x=5x = 5 is vertical, so any line perpendicular to it must be horizontal, with slope 00. Substituting m=0m_\perp = 0 and (x1,y1)=(3,2)(x_1, y_1) = (3, -2):

yy1=m(xx1)y(2)=0(x3)y+2=0y=2 \begin{align} y - y_1 &= m(x - x_1) \\ y - (-2) &= 0(x - 3) \\ y + 2 &= 0 \\ y &= -2 \end{align}

Example. Find an equation of a line perpendicular to y=4y = -4 that contains the point (4,2)(-4, 2). Write the equation in slope-intercept form.

The line y=4y = -4 is horizontal, so any line perpendicular to it must be vertical, in the form x=ax = a. Since the perpendicular line passes through (4,2)(-4, 2), every point on it has xx-coordinate 4-4. The equation of the perpendicular line is x=4x = -4.

Find an equation of a line perpendicular to the line y=12x3y = \tfrac{1}{2} x - 3 that contains the point (6,4)(6, 4). Write the equation in slope-intercept form.

A line is perpendicular to x=4x = 4. What form must its equation take?

Key terms

point-slope form — the form yy1=m(xx1)y - y_1 = m(x - x_1) of an equation of a line with slope mm that contains the point (x1,y1)(x_1, y_1); useful whenever the slope and any one point (not necessarily the yy-intercept) are known, or when two points are known and the slope is found first.


This section is adapted from Elementary Algebra 2e, Section 4.6: Find the Equation of a Line by Lynn Marecek, MaryAnne Anthony-Smith, and Andrea Honeycutt Mathis, © OpenStax, licensed under CC BY-NC-SA 4.0. Access the original for free at openstax.org. Changes: condensed the worked examples and tables; omitted the Be Prepared quiz, Media links, Self Check checklist, and Section Exercises; and converted the practice problems (“Try Its”) into interactive exercises with instant feedback.