Systems and Inequalities

Cramer's Rule for Two Equations in Two Unknowns

Solve a two-by-two linear system with determinants, see where the formula comes from, and know what a zero determinant means.

Key takeaways

  • Both unknowns share one denominator, D = ad - bc, called the determinant of the coefficients.
  • The numerator for x comes from replacing the x coefficients with the constants, and similarly for y.
  • The rule applies only when D ≠ 0, and then the solution is unique.
  • When D = 0, the system has either no solution or infinitely many, and you must check which.
  • The equations must be in standard form before you read off any numbers.

Cramer's rule gives the solution of two linear equations in two unknowns directly, as a quotient of two small calculations for each variable. For the system ax + by = e and cx + dy = f, the solution is

x = (ed - bf) / (ad - bc)        y = (af - ec) / (ad - bc)

provided that ad - bc is not zero. The rule is named for Gabriel Cramer, an eighteenth-century Swiss mathematician who published a general version of it.

Determinants of a two-by-two array

Arrange four numbers in a square. The determinant is the product of the main diagonal minus the product of the other diagonal.

| p  q |
| r  s |   =  ps - qr

For instance, with rows (3, 2) and (5, -1), the determinant is 3(-1) - 2(5) = -13. The order of subtraction matters, since reversing it changes the sign.

Cramer's rule uses three of these arrays.

D  = | a  b |      Dx = | e  b |      Dy = | a  e |
     | c  d |           | f  d |           | c  f |

x = Dx / D          y = Dy / D

In Dx the first column, which held the x coefficients, is replaced by the constants. In Dy the second column is replaced.

A worked example

3x + 2y = 12
5x -  y = 7

Here a = 3, b = 2, c = 5, d = -1, e = 12 and f = 7.

D  = (3)(-1) - (2)(5)    = -3 - 10   = -13
Dx = (12)(-1) - (2)(7)   = -12 - 14  = -26
Dy = (3)(7) - (12)(5)    = 21 - 60   = -39

x = -26 / -13 = 2
y = -39 / -13 = 3

The solution is (2, 3). Check: 6 + 6 = 12, and 10 - 3 = 7.

Applying Cramer's rule
1 Standard form Write both equations as ax + by = constant. 2 Find D Compute ad - bc. If it is zero, stop and examine the system. 3 Find Dx and Dy Swap the constants into one column at a time. 4 Divide and check x = Dx / D and y = Dy / D, then substitute back. Standard form Write both equations as ax + by = constant. 1 Find D Compute ad - bc. If it is zero, stop and examine the system. 2 Find Dx and Dy Swap the constants into one column at a time. 3 Divide and check x = Dx / D and y = Dy / D, then substitute back. 4

Where the formula comes from

The rule is nothing more than elimination done once with letters.

ax + by = e
cx + dy = f

To remove y:  multiply the first by d, the second by b
              adx + bdy = ed
              bcx + bdy = bf
              subtract:   (ad - bc)x = ed - bf

To remove x:  multiply the first by c, the second by a
              acx + bcy = ec
              acx + ady = af
              subtract:   (ad - bc)y = af - ec

If ad - bc ≠ 0, divide, and the formulas appear. Each step is the ordinary method of elimination. Because the letters can stand for any numbers, you never need to repeat the work.

The derivation shows that any solution must equal these values. Substituting them back into the original equations confirms that they really do satisfy both, so a solution exists and it is the only one.

Standard form first

The numbers must be read from lined-up equations. Consider this pair.

y = 2x - 5
3x + 4y = 13

Rewrite the first as -2x + y = -5. Now a = -2, b = 1, e = -5, c = 3, d = 4, f = 13.

D  = (-2)(4) - (1)(3)      = -11
Dx = (-5)(4) - (1)(13)     = -33
Dy = (-2)(13) - (-5)(3)    = -26 + 15  = -11

x = 3,   y = 1

Check: 2(3) - 5 = 1, and 9 + 4 = 13. For this particular system, substitution would be at least as quick, since y was already isolated.

A missing variable counts as a coefficient of zero. The equation 4x = 8 means a = 4 and b = 0.

When the determinant is zero

If D = 0, you cannot divide, and the formulas say nothing directly. Look at these two systems.

System D Dx Dy Outcome
2x + 4y = 6 and x + 2y = 3 0 0 0 infinitely many
2x + 4y = 6 and x + 2y = 5 0 -8 4 none

The derivation explains the table. It shows that D · x = Dx and D · y = Dy for any solution. If D = 0 while Dx or Dy is not zero, one of these reads 0 = nonzero, so there is no solution.

If all three are zero and at least one of a, b, c, d is nonzero, then one equation is a multiple of the other, the one it copies describes a line, and there are infinitely many solutions. The condition on the coefficients matters in degenerate cases. The "system" 0x + 0y = 1 and 0x + 0y = 2 has all three determinants zero and no solution at all. The three cases in general are covered in consistent, inconsistent and dependent systems.

Fractional answers and letters

Cramer's rule is at its best when the answers are unpleasant. For 7x + 3y = 5 and 2x + 5y = 3:

D  = 35 - 6   = 29
Dx = 25 - 9   = 16
Dy = 21 - 10  = 11
x = 16/29,   y = 11/29

No back-substitution of fractions is needed.

It is equally convenient with parameters. Solve kx + y = 3 and x + ky = 3.

D  = k² - 1
Dx = 3k - 3
Dy = 3k - 3
x = y = 3(k - 1) / (k² - 1) = 3 / (k + 1),    for k ≠ 1 and k ≠ -1

When k = 1, both equations become x + y = 3, giving infinitely many solutions. When k = -1, they read -x + y = 3 and x - y = 3, and adding gives 0 = 6, so there is none. The determinant told you exactly which values to inspect.

Solving for just one unknown

Because each variable has its own formula, you can compute one without touching the other. Suppose a question about the system 13x + 4y = 50 and 7x + 3y = 31 asks only for y.

D  = (13)(3) - (4)(7)      = 39 - 28    = 11
Dy = (13)(31) - (50)(7)    = 403 - 350  = 53
y  = 53/11

That is the whole job: two determinants and one division. Finding x would take only one more, Dx = (50)(3) - (4)(31) = 26, giving x = 26/11. As a check, 13(26/11) + 4(53/11) = (338 + 212)/11 = 550/11 = 50, and 7(26/11) + 3(53/11) = (182 + 159)/11 = 341/11 = 31.

A word problem

Say a shop mixes two bundles. A small bundle holds 2 candles and 1 holder, and a large one holds 5 candles and 3 holders. On one day the bundles used 44 candles and 25 holders. How many of each were made?

Let s and g be the numbers of small and large bundles. Count candles, then holders.

2s + 5g = 44
 s + 3g = 25

D  = (2)(3) - (5)(1)       = 1
Dx = (44)(3) - (5)(25)     = 132 - 125  = 7
Dy = (2)(25) - (44)(1)     = 50 - 44    = 6

So there were 7 small and 6 large bundles. Check: 14 + 30 = 44 candles, and 7 + 18 = 25 holders. A determinant of 1 means no division was needed, and whole-number constants were bound to give whole-number answers. With other determinants, a fractional result in a counting problem would signal inconsistent data or a setup error.

How sensitive is the answer?

The constants appear only in the numerators. If a constant changes by a small amount, each unknown changes by that amount times a coefficient, divided by D. In the bundle problem, using 45 candles instead of 44 changes s by d/D = 3 and g by -c/D = -1. The new solution is s = 10, g = 5, which uses 20 + 25 = 45 candles and 10 + 15 = 25 holders. When D is tiny compared with the coefficients, these shifts become enormous.

A geometric meaning

The columns (a, c) and (b, d) can be drawn as arrows from the origin. The absolute value of D is the area of the parallelogram they span. If D = 0, the arrows lie along one line, the parallelogram is flat, and combinations of the two arrows can reach only points on that line.

Solving the system means finding how many copies x of the first arrow and y of the second add up to the arrow (e, f). When the arrows point in genuinely different directions, there is exactly one recipe. More about this measure is in what a determinant measures.

Checking Cramer's rule against another method

It pays to run one familiar system both ways. Take x + 2y = 8 and 3x - y = 3.

By determinants, D = (1)(-1) - (2)(3) = -7. Then Dx = (8)(-1) - (2)(3) = -14, and Dy = (1)(3) - (8)(3) = -21. So x = 2 and y = 3.

By substitution, x = 8 - 2y, so 3(8 - 2y) - y = 3. That gives 24 - 7y = 3, so y = 3 and x = 2.

The agreement is no accident. In the substitution route, the coefficient -7 that you divided by is the determinant. Every method for this system has to divide by that number at some stage, in one disguise or another, which is why a zero determinant causes trouble no matter how you solve.

Interchanging the two equations changes the sign of D, Dx and Dy together, so the quotients stay the same. Multiplying one equation by 10 multiplies all three by 10, with the same result. These facts are a handy test of your arithmetic.

When to use it, and when not

Cramer's rule suits two-by-two systems with awkward numbers or letters, questions that ask for only one of the variables, and checks of work done another way.

It is less attractive when a variable is already isolated or the coefficients cancel at a glance. For larger systems, the number of calculations in the determinants grows quickly, and computers use elimination-style methods. The general version and its limits are discussed in Cramer's rule in general.

With decimal data there is one more caution. If D is very close to zero, small changes in the coefficients can change the answer a great deal. Keep full precision until the final step.

Mistakes to avoid

  • Reading from unaligned equations. Rearrange first, and keep the signs with their coefficients.
  • Replacing the wrong column. Dx replaces the x column, Dy the y column.
  • Subtracting in the wrong order. Always down-right product minus the other.
  • Inverting the quotient. The shared determinant D goes in the denominator.
  • Declaring "no solution" whenever D = 0. Check Dx, Dy and the equations themselves.

Written for 4Algebra with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 28 articles in Systems and Inequalities →

Latest news on this topic