Linear Equations: Straight Lines, Slopes and Solutions

A complete, plain-language guide with worked examples, diagrams, tables and links to AI and machine learning

In this article
  1. Introduction
  2. What is a linear equation?
  3. Solving one-variable equations
  4. Variables on both sides
  5. Special cases
  6. Slope and intercept
  7. Graphing a line
  8. Writing the equation of a line
  9. Parallel and perpendicular lines
  10. Systems of linear equations
  11. Real-world problems
  12. AI and machine learning
  13. Common mistakes
  14. Practice problems
  15. Conclusion

1. Introduction

Linear equations are among the most useful ideas in mathematics. They describe situations where one quantity changes at a steady rate: a taxi fare that grows with distance, a savings account that gains the same deposit each month, or a car travelling at constant speed. Whenever you can say "for every one more of this, there are always so many more of that," a linear equation is hiding in the sentence.

The word linear comes from line. Plot the solutions of a linear equation in two variables and you always get a straight line. This single fact connects algebra, which manipulates symbols, with geometry, which studies shapes, and it makes linear equations the natural next step after variables and expressions.

In this article we define linear equations, learn to solve them, interpret slope and intercept, graph lines, write equations from data, and solve systems of two equations. We finish with the role linear equations play in machine learning, where fitting a line to data is one of the oldest and still most widely used techniques.

2. What is a linear equation?

A linear equation is an equation in which every variable appears only to the first power and is never multiplied by another variable. So 3x + 2 = 11 and y = 2x + 1 are linear, while x² + 1 = 5, xy = 6 and y = √x are not. Unlike an expression, an equation contains an equals sign and states that two quantities are the same. Solving it means finding the values of the variable that make that statement true.

Linear equations come in several standard forms, and each is convenient for a different job.

Standard forms of linear equations
NameFormBest used for
One variableax + b = cfinding a single unknown
Slope-intercepty = mx + bgraphing and reading slope
StandardAx + By = Cfinding intercepts, systems
Point-slopey − y₁ = m(x − x₁)building a line from a point

In one variable there is usually exactly one solution. In two variables there are infinitely many solutions, each an ordered pair (x, y), and together they form a line.

3. Solving one-variable equations

An equation is like a balance scale. If the two sides are equal and you do the same thing to both, they stay equal. That principle is the whole method: to isolate the variable, undo the operations applied to it, working in reverse order, using inverse operations. Addition is undone by subtraction, and multiplication is undone by division.

Take 3x + 2 = 11. The variable has been multiplied by 3 and then increased by 2, so we undo the addition first by subtracting 2 from both sides, giving 3x = 9. Then we divide both sides by 3 to get x = 3. Substituting back confirms it, since 3(3) + 2 = 11.

Flow showing the steps to solve 3x + 2 = 11
Solving by keeping the equation balanced.

Fractions and brackets need one extra idea. For x/4 − 1 = 2, add 1 to get x/4 = 3, then multiply both sides by 4 to find x = 12. For 2(x − 3) = 10, you can either divide both sides by 2 first, giving x − 3 = 5 and x = 8, or distribute to get 2x − 6 = 10, then 2x = 16 and x = 8. Both routes agree. Whatever the route, finish with a check.

Equations with decimals work the same way. In 0.5x + 1.2 = 4.7, subtract 1.2 to get 0.5x = 3.5 and divide by 0.5 to find x = 7. If decimals feel awkward, multiply every term by 10 or 100 first to clear them, which turns the equation into one with whole numbers and does not change its solution.

4. Variables on both sides

When the variable appears on both sides, the goal is to gather all variable terms on one side and all constants on the other. Then it becomes an ordinary one-step-at-a-time problem. Consider 5x − 7 = 2x + 8.

Solving 5x − 7 = 2x + 8 step by step
StepEquationWhat we did
15x − 7 = 2x + 8start
23x − 7 = 8subtract 2x from both sides
33x = 15add 7 to both sides
4x = 5divide both sides by 3
Check5(5) − 7 = 18 = 2(5) + 8both sides equal 18

A handy habit is to move the smaller variable term so that the coefficient stays positive, but the answer is the same either way.

5. Special cases

Not every linear equation has exactly one solution. After simplifying, one of three things happens. If the variable survives, there is one solution. If the variable cancels and what remains is false, such as 3 = 5, no value works and there is no solution. If the variable cancels and what remains is always true, such as 2 = 2, every number works and there are infinitely many solutions.

The three possible outcomes
EquationAfter simplifyingResult
3x + 1 = 7x = 2one solution
2x + 3 = 2x + 53 = 5 (false)no solution
2(x + 1) = 2x + 22 = 2 (true)infinitely many solutions

6. Slope and intercept

The slope-intercept form y = mx + b packs two facts into one line. The number m is the slope, which measures steepness: how much y changes for each one-unit step in x. The number b is the y-intercept, the height where the line crosses the y-axis, because setting x = 0 leaves y = b.

Slope is rise over run. Between two points (x₁, y₁) and (x₂, y₂) it equals m = (y₂ − y₁) / (x₂ − x₁). In the line y = 2x + 1, moving 2 units right raises the line by 4, so the slope is 4/2 = 2.

Graph of y = 2x + 1 with rise, run and intercept marked
Reading slope and intercept from the graph of y = 2x + 1.

The sign of the slope tells you the direction of the line, and the special cases of zero and undefined slope are worth memorising.

Four small graphs showing positive, negative, zero and undefined slope
The four kinds of slope.
Kinds of slope
SlopeDirectionExample
positiverises from left to righty = 2x
negativefalls from left to righty = −x + 3
zerohorizontaly = 4
undefinedverticalx = 3

Slope is also a rate of change, which is why it appears everywhere. A taxi that charges 1.5 dollars per kilometre has slope 1.5. A car travelling at 60 kilometres per hour has a distance-time graph with slope 60. A negative slope describes something shrinking, such as a phone battery that loses 5 percent of its charge every hour. Whenever you read a slope, attach units to it: dollars per kilometre, kilometres per hour, percent per hour.

7. Graphing a line

The most reliable way to graph a line is to build a table of values. Choose several values of x, substitute each into the equation to get y, and plot the pairs. Two points are enough to fix a straight line, but a third acts as a check. For y = −x + 3 the table below gives five points, and they all fall on one line.

Table of values for y = −x + 3
xCalculationyPoint
−1−(−1) + 34(−1, 4)
0−(0) + 33(0, 3)
1−(1) + 32(1, 2)
2−(2) + 31(2, 1)
3−(3) + 30(3, 0)
Graph of y = −x + 3 with five plotted points
Five points from the table lie on one straight line.

A second method uses the intercepts. For 2x + 3y = 6, set x = 0 to get y = 2, and set y = 0 to get x = 3. Plot (0, 2) and (3, 0) and draw the line through them. A third method starts at the y-intercept and uses the slope: from (0, b), move right by the run and up by the rise.

8. Writing the equation of a line

Often you are given information about a line and must write its equation. If you know the slope m and one point (x₁, y₁), the point-slope form y − y₁ = m(x − x₁) gives the line directly. If you know two points, find the slope first and then use either point.

Finding the line through (1, 3) and (3, 7)
StepWorkResult
Slopem = (7 − 3) / (3 − 1)m = 2
Intercept3 = 2(1) + bb = 1
Equationsubstitute m and by = 2x + 1
Check2(3) + 1 = 7the second point fits

The equation y = 2x + 1 is the same line we graphed earlier. Notice the logic: slope comes from the difference between points, and the intercept comes from forcing the equation to pass through one of them.

Equations given in standard form can be converted. Starting from 2x + 3y = 6, subtract 2x from both sides to get 3y = −2x + 6, then divide everything by 3 to reach y = −(2/3)x + 2. Now the slope, −2/3, and the y-intercept, 2, can be read straight off. This agrees with the intercepts found earlier, since the line crosses the y-axis at 2.

9. Parallel and perpendicular lines

Two lines in a plane either cross, run side by side forever, or coincide. Lines with the same slope never meet, so they are parallel. Lines whose slopes multiply to −1 meet at a right angle and are perpendicular. The line y = 2x + 1 is parallel to y = 2x − 2, and perpendicular to any line with slope −1/2.

Three lines showing parallel and perpendicular relationships
Parallel lines share a slope; perpendicular slopes multiply to −1.
Slope rules for pairs of lines
RelationshipRuleExample slopes
Parallelm₁ = m₂2 and 2
Perpendicularm₁ × m₂ = −12 and −1/2

Why do perpendicular slopes multiply to −1? Turn a line a quarter of a turn and its run and rise swap roles, with one of them changing sign. A line that rises 2 for every 1 across becomes a line that falls 1 for every 2 across, so the slope 2 becomes −1/2, and 2 × (−1/2) = −1. This rule is useful in geometry, for example when finding the shortest path from a point to a line.

10. Systems of linear equations

A system of linear equations is a set of two or more equations that must hold at the same time. For two variables, the solution is the pair (x, y) that satisfies both. Graphically it is the point where the two lines cross.

Two lines crossing at the point (2, 3)
The system y = 2x − 1 and y = −x + 5 has the solution (2, 3).

Substitution replaces one variable using the other equation. Here both equations give y, so set them equal: 2x − 1 = −x + 5. Then 3x = 6, so x = 2, and y = 2(2) − 1 = 3. Elimination adds or subtracts the equations to cancel a variable. For x + y = 7 and x − y = 1, adding gives 2x = 8, so x = 4, and then y = 3.

Sometimes the coefficients do not line up, and you must scale one equation first. For 2x + 3y = 12 and x − y = 1, multiply the second equation by 3 to get 3x − 3y = 3. Adding it to the first cancels y and gives 5x = 15, so x = 3. Then 3 − y = 1 gives y = 2. Check both: 2(3) + 3(2) = 12 and 3 − 2 = 1.

Methods for solving a system
MethodIdeaHandy when
Graphingdraw both lines, find the crossingyou want a picture
Substitutionreplace one variable with an expressionone equation is already solved for a variable
Eliminationadd or subtract to cancel a variablecoefficients line up or are easy to match

As with single equations, a system can have one solution, none or infinitely many, depending on whether the lines cross, are parallel or are the same line.

Three small graphs of crossing, parallel and coincident lines
The three possible outcomes for a system of two linear equations.

11. Real-world problems

Linear equations model any situation with a fixed starting amount plus a constant rate. Suppose Plan A costs 10 dollars plus 2 dollars per gigabyte, so C = 10 + 2g, and Plan B costs 20 dollars plus 1 dollar per gigabyte, so C = 20 + g. Which is cheaper? Setting the costs equal gives 10 + 2g = 20 + g, so g = 10. At 10 gigabytes both cost 30 dollars. Below that Plan A wins, and above it Plan B wins.

Monthly cost of two phone plans
Data g (GB)Plan A: 10 + 2gPlan B: 20 + gCheaper
01020A
52025A
103030equal
154035B
205040B

The break-even point is simply the solution of a system. Questions about when two options cost the same, when two moving objects meet, or when a business covers its costs all reduce to solving a linear system.

12. AI and machine learning

Linear equations sit at the foundation of machine learning. The simplest model, linear regression, predicts a target with ŷ = wx + b. This is exactly y = mx + b with new names: the slope is called the weight w, and the intercept is called the bias b. Training means choosing w and b so that the line passes as close as possible to the data, usually by making the sum of squared vertical errors small.

Scatter plot with a fitted line and vertical error segments
Linear regression fits a line by making the errors small.

Where do the best values of w and b come from? With exactly two points there is exactly one line through them, and finding it means solving a system of two linear equations. With many noisy points no single line passes through all of them, so training searches for the line with the smallest total error. Either way the model is the same simple equation, and only the method of choosing its two numbers changes.

With several inputs the same idea becomes ŷ = w₁x₁ + w₂x₂ + … + b. Each layer of a neural network begins with a linear step z = Wx + b. A linear classifier separates two classes with the boundary w₁x₁ + w₂x₂ + b = 0, which is a straight line in two dimensions. Fitting these models also relies on solving linear systems, which is why efficient algorithms for them are so important.

Linear steps alone are limited. Stacking linear layers without anything else still gives one linear function, so neural networks insert non-linear activation functions between them. But every one of those layers still starts with the linear equation you have just studied.

The same ideas, two vocabularies
AlgebraMachine learning
slope mweight w
y-intercept bbias b
xfeature (input)
ytarget or label (output)
the linethe model
finding m and b from pointstraining or fitting

13. Common mistakes

Frequent mistakes and corrections
MistakeWrongRight
Changing only one side3x + 2 = 11 → 3x = 113x = 9
Sign error when moving a term3x − 5 = 10 → 3x = 53x = 15
Not distributing to every term2(x + 3) = 2x + 32x + 6
Inverting the slopem = run / risem = rise / run
Confusing zero and undefined slopevertical line has slope 0vertical is undefined; horizontal is 0
Skipping the checktrusting the answersubstitute it back

14. Practice problems

Try these before looking at the answers.

  1. Solve 4x − 9 = 15.
  2. Solve 3(x + 2) = 21.
  3. Solve 5x − 3 = 2x + 12.
  4. Find the slope of the line through (2, 1) and (6, 9).
  5. Write the equation of the line with slope −3 and y-intercept 4.
  6. Solve the system x + y = 10 and x − y = 2.
  7. Are y = 3x + 1 and y = 3x − 5 parallel, crossing or the same line?

Answers.

  1. 4x = 24, so x = 6.
  2. x + 2 = 7, so x = 5.
  3. 3x = 15, so x = 5.
  4. (9 − 1) / (6 − 2) = 2.
  5. y = −3x + 4.
  6. Adding gives 2x = 12, so x = 6 and y = 4.
  7. Same slope 3 but different intercepts, so they are parallel and the system has no solution.

15. Conclusion

A linear equation says that two quantities stay in step: change one by a fixed amount and the other changes by a fixed multiple of it. That simple idea has a dependable solving method, the balance principle, and a clean geometric picture, a straight line described by a slope and an intercept.

Once you can solve one equation, graph a line, write an equation from two points and handle a system of two equations, you are ready for quadratic equations, functions and the models used throughout data science. Practise with a check after every solution, and the habit will serve you in every later topic.