Why AB Differs from BA

Swap the order of a product and the answer moves.

The same two matrices, two products

Take A = (1 2; 0 1) and B = (1 0; 1 1). In AB, the rows of A meet the columns of B. Row 1 of A is 1, 2, so the top row of AB is 1 × 1 + 2 × 1 = 3 and 1 × 0 + 2 × 1 = 2. Row 2 of A is 0, 1, so the bottom row is 0 × 1 + 1 × 1 = 1 and 0 × 0 + 1 × 1 = 1. So AB = (3 2; 1 1).

In BA, the rows of B meet the columns of A. Row 1 of B is 1, 0, so the top row of BA is 1 × 1 + 0 × 0 = 1 and 1 × 2 + 0 × 1 = 2. Row 2 of B is 1, 1, so the bottom row is 1 × 1 + 1 × 0 = 1 and 1 × 2 + 1 × 1 = 3. So BA = (1 2; 1 3).

A1201B1011AB3211×=

In AB, the bottom right entry comes from row 2 of A and column 2 of B: 0 × 0 + 1 × 1 = 1.

B1011A1201BA1213×=

In BA, the bottom right entry comes from row 2 of B and column 2 of A: 1 × 2 + 1 × 1 = 3.

Not commutative

For numbers, 3 × 5 = 5 × 3: multiplication of numbers is commutative. For matrices, AB and BA are usually different, as the pair above shows. Matrix multiplication is not commutative.

The reason is in the rule itself. Each entry pairs a row of the left matrix with a column of the right one, so swapping the two matrices changes which numbers are paired. The top left entry of AB pairs row 1 of A, which is 1, 2, with column 1 of B, which is 1, 1. The top left entry of BA pairs row 1 of B, which is 1, 0, with column 1 of A, which is 1, 0. Different numbers go in, so different numbers come out.

So the order of a product has to be said. In AB, A is on the left and B is on the right; in BA, B is on the left.

Swapping rows, swapping columns

The matrix S = (0 1; 1 0) shows what the order does. With M = (1 2; 3 4), row 1 of S is 0, 1, so each entry in the top row of SM takes 0 of row 1 of M and 1 of row 2: the top row of SM is row 2 of M. Row 2 of S picks out row 1 of M in the same way. So SM = (3 4; 1 2): S on the left swaps the rows of M.

On the right, S acts on columns instead. Column 1 of S is 0, 1, so the first column of MS is column 2 of M, and the second column of MS is column 1 of M. So MS = (2 1; 4 3): S on the right swaps the columns of M.

S0110M1234SM3412×=

S on the left: row 2 of M, which is 3, 4, becomes the top row of SM.

M1234S0110MS2143×=

S on the right: column 2 of M, which is 2 above 4, becomes the first column of MS.

Products of different orders

When the matrices are not square, AB and BA need not even be the same size. For A = (2 3 1; 4 0 2), a 2 × 3, and B = (5 4; 1 0; 3 2), a 3 × 2, AB is a 2 × 2, (16 10; 26 20). BA is a 3 × 2 times a 2 × 3, so it is a 3 × 3.

Each row of B, which holds 2 entries, meets each column of A, which holds 2 as well. Row 1 of B is 5, 4: with the columns of A it gives 5 × 2 + 4 × 4 = 26, 5 × 3 + 4 × 0 = 15 and 5 × 1 + 4 × 2 = 13. Row 2 is 1, 0, giving 2, 3 and 1. Row 3 is 3, 2, giving 3 × 2 + 2 × 4 = 14, 3 × 3 + 2 × 0 = 9 and 3 × 1 + 2 × 2 = 7. So BA = (26 15 13; 2 3 1; 14 9 7).

Sometimes only one of the two products exists. A 2 × 3 times a 3 × 1 is a 2 × 1, but a 3 × 1 times a 2 × 3 cannot be found, because the inner numbers 1 and 2 do not match.

B541032A231402BA2615132311497×=

BA is 3 × 3. Its top left entry is row 1 of B with column 1 of A: 5 × 2 + 4 × 4 = 26.

Pairs that do commute

Not commutative means that AB = BA cannot be assumed, not that it never happens. A matrix commutes with itself, since A × A is A × A either way, and with any scalar multiple of itself. Two diagonal matrices commute: (2 0; 0 3)(4 0; 0 5) = (8 0; 0 15), and so does (4 0; 0 5)(2 0; 0 3).

Addition is different. Each entry of A + B is a sum of two numbers in the same place, so A + B = B + A for any two matrices of the same order.

Keeping the order in algebra

For numbers, (a + b)² = a² + 2ab + b², because ab and ba are the same. For matrices, (A + B)² means (A + B)(A + B), which multiplies out to AA + AB + BA + BB. The middle terms AB and BA cannot be combined into 2AB.

Check it with A = (1 2; 0 1) and B = (1 0; 1 1). A + B = (2 2; 1 2), and squaring it row by column gives 2 × 2 + 2 × 1 = 6, 2 × 2 + 2 × 2 = 8, 1 × 2 + 2 × 1 = 4 and 1 × 2 + 2 × 2 = 6, so (A + B)² is the matrix (6 8; 4 6).

Now AA = (1 4; 0 1), BB = (1 0; 2 1), AB = (3 2; 1 1) and BA = (1 2; 1 3). Adding the four entry by entry gives 1 + 3 + 1 + 1 = 6, 4 + 2 + 2 + 0 = 8, 0 + 1 + 1 + 2 = 4 and 1 + 1 + 3 + 1 = 6, which is (6 8; 4 6) again. Using 2AB in place of AB + BA gives (8 8; 4 4), which is wrong.

The usual mistakes

Assuming that AB = BA, as it would be for two numbers. For A = (1 2; 0 1) and B = (1 0; 1 1), the top left entries are 3 and 1.

Reusing an entry of AB for BA. The bottom right entry of AB is 1, but the bottom right entry of BA is 3: each has to be worked out from its own row and column.

Taking the order of BA to be the order of AB. For a 2 × 3 matrix A and a 3 × 2 matrix B, AB is 2 × 2 and BA is 3 × 3.

Boxes and fruit

In the application below, one matrix counts the boxes in each order and another counts the fruit in each box. Multiplied in the order in which the labels meet, they count the fruit in each order. Multiplied the other way round, they give a different matrix whose entries count nothing.

Worked example: Fruit Boxes in Two Orders, Where AB Counts the Fruit and BA Counts Nothing

Question A farm packs small and large fruit boxes. A small box holds 6 apples and 4 pears, and a large box holds 10 apples and 8 pears. Order 1 is 3 small boxes and 1 large box, and order 2 is 2 small boxes and 4 large boxes. Let A = 3124, with the orders in the rows and the small and large boxes in the columns, and let B = 64108, with the box sizes in the rows and apples and pears in the columns. (a) Find AB and say what it tells the farm. (b) Find BA. Show that AB ≠ BA, and explain why BA does not count anything.

  1. 1.In AB a row of A, one order by box size, meets a column of B, one fruit by box size. The box sizes match, so each entry of AB counts one fruit in one order.

    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large108A: orders to boxes. B: boxes to fruitin AB the boxes meet
    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large108A: orders to boxes. B: boxes to fruitin AB the boxes meet
    A = 3124 has the orders in its rows and the box sizes in its columns; B = 64108 has the box sizes in its rows. In AB the box sizes meet.
  2. 2.Row 1 times column 1: 3 × 6 + 1 × 10 = 28 apples in order 1. Row 1 times column 2: 3 × 4 + 1 × 8 = 20 pears. Row 2 gives 2 × 6 + 4 × 10 = 52 apples and 2 × 4 + 4 × 8 = 40 pears.

    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large1083124×64108=2820??3 × 6 + 1 × 10 = 28 apples in order 12 × 6 + 4 × 10 = 52, 2 × 4 + 4 × 8 = 40
    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large1083124×64108=2820??3 × 6 + 1 × 10 = 28 apples in order 12 × 6 + 4 × 10 = 52, 2 × 4 + 4 × 8 = 40
    Row 1 of A times column 1 of B: 3 × 6 + 1 × 10 = 28 apples in order 1.
  3. 3.(a) AB = 28205240: order 1 needs 28 apples and 20 pears, and order 2 needs 52 apples and 40 pears.

    AB: fruit in each orderapplespearsorder 12820order 25240AB =28205240order 1: 28 apples, 20 pearsorder 2: 52 apples, 40 pears
    AB: fruit in each orderapplespearsorder 12820order 25240AB =28205240order 1: 28 apples, 20 pearsorder 2: 52 apples, 40 pears
    (a) AB = 28205240: the apples and pears in each order.
  4. 4.Now multiply the other way round, a row of B times a column of A: 6 × 3 + 4 × 2 = 26, 6 × 1 + 4 × 4 = 22, 10 × 3 + 8 × 2 = 46 and 10 × 1 + 8 × 4 = 42. So BA = 26224642.

    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large10864108×3124=262246426 × 3 + 4 × 2 = 26
    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large10864108×3124=262246426 × 3 + 4 × 2 = 26
    The other way round, row 1 of B times column 1 of A: 6 × 3 + 4 × 2 = 26, and BA = 26224642.
  5. 5.(b) The first entries are 28 and 26, so AB ≠ BA. The first entry of BA is 6 × 3 + 4 × 2: the apples in a small box times the small boxes in order 1, plus the pears in a small box times the small boxes in order 2. It adds two kinds of fruit from two different orders, so it counts nothing. Matrices must be multiplied in the order in which their labels meet: orders to boxes, then boxes to fruit.

    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large10828 is not 26, so AB and BA differ6 × 3: apples in a small box, order 14 × 2: pears in a small box, order 2two fruits, two orders: it counts nothing
    A: boxes in each ordersmalllargeorder 131order 224B: fruit in each boxapplespearssmall64large10828 is not 26, so AB and BA differ6 × 3: apples in a small box, order 14 × 2: pears in a small box, order 2two fruits, two orders: it counts nothing
    (b) AB ≠ BA. Row 1 of B is a small box by fruit and column 1 of A is small boxes by order, so BA pairs fruit with orders and counts nothing.

Answer: (a) AB = 28205240: order 1 needs 28 apples and 20 pears, and order 2 needs 52 apples and 40 pears; (b) BA = 26224642 ≠ AB, and its entries add fruit of two kinds from two orders, so it counts nothing

Common mistakes

  • Assuming that AB = BA, as it would be for two numbers. Matrix multiplication is not commutative: here the first entries are 28 and 26.
  • Reading the 46 in BA as the apples in order 2. Only a product whose inner labels match counts something; in BA the columns of B are fruit and the rows of A are orders, and those do not match.

More matrix arithmetic problems, worked step by step →

Practice Why AB Differs from BA in the app