MatrixStep

Guides7 min

Matrix Multiplication Rules

Matrix multiplication looks like ordinary multiplication but follows a few different rules. The sizes have to fit, swapping the order changes the answer, and a product can be zero without either factor being zero. This guide checks each rule that holds, and each one that fails, with a worked example. For how to compute a product entry by entry, see how to multiply matrices.

Rule 1. The size condition: (m×n)(n×p) = m×p

AB is defined only when A is m×n and B is n×p, and then AB is m×p. The number of columns of A must equal the number of rows of B. The two inner numbers must match and cancel; the two outer numbers give the size of the result.

So for non-square matrices it is common that AB exists while BA does not.

Rule 2. Multiplication is not commutative: AB ≠ BA

A =1234B =0110
AB =2143BA =3412

B is the matrix that swaps two columns (or two rows). Multiplying on the right swaps the columns of A; multiplying on the left swaps the rows. Both products are defined and have the same size, but the entries differ.

When AB = BA does hold

e.g.2003500−1=500−12003=1000−3

Outside these special cases, assume AB and BA are different.

Rule 3. Multiplication is associative: (AB)C = A(BC)

It does not matter which product you compute first, so ABC can be written without parentheses.

(AB)C =21432011=51113
A(BC) =12341120=51113

You may move the parentheses, but not the order of A, B and C.

Rule 4. Multiplication distributes over addition

A(B + C) = AB + AC(A + B)C = AC + BC
A(B + C) =12342121=63147

Keep track of which side you multiply on. Writing A(B + C) as BA + CA is wrong.

Rule 5. The identity and the zero matrix

11111−1−11=0000

Neither factor is zero, yet the product is the zero matrix. For the same reason there is no cancellation law: AB = AC does not imply B = C.

11111001=1111,11110110=1111

To get from AB = AC to B = C you need A to be invertible; then multiply both sides on the left by A⁻¹.

Rule 6. Scalars can move anywhere

k(AB) = (kA)B = A(kB)

A number k can be moved freely through a matrix product. Matrices cannot be reordered, but scalars can.

Rule 7. Transpose, inverse and determinant of a product

(AB)ᵀ = BᵀAᵀ(AB)⁻¹ = B⁻¹A⁻¹det(AB) = det(A)·det(B)

For the transpose and the inverse the order reverses, like taking off clothes in the opposite order you put them on. Checking with the example:

(AB)ᵀ =2413BᵀAᵀ =2413AᵀBᵀ =3142

(AB)ᵀ = BᵀAᵀ holds, while AᵀBᵀ is a different matrix. Only the determinant, being a number, does not care about order.

Rule 8. Expanding products: (A + B)² ≠ A² + 2AB + B²

(A + B)² = (A + B)(A + B) = A² + AB + BA + B²

Because AB and BA differ, they cannot be merged into 2AB. The familiar expansion holds only when AB = BA. Likewise (A + B)(A − B) = A² − AB + BA − B², which is not A² − B².

Summary table

RuleHolds?Note
Size condition (m×n)(n×p)requiredotherwise undefined
Commutative AB = BA✗only in special cases
Associative (AB)C = A(BC)✓parentheses are free
Distributive A(B+C) = AB + AC✓keep left/right
AI = IA = A✓
AB = 0 ⇒ A = 0 or B = 0✗zero divisors exist
AB = AC ⇒ B = C✗only if A is invertible
(AB)ᵀ = BᵀAᵀ✓order reverses
(AB)⁻¹ = B⁻¹A⁻¹✓order reverses
det(AB) = det A · det B✓

To see AB and BA side by side with your own numbers, enter two matrices in the matrix multiplication calculator and swap them. It shows every entry's computation.

FAQ

Is there a quick test for AB = BA?

No shortcut in general; you have to compute both. But if one matrix is the identity, a scalar matrix, a power of the other, or the other's inverse, or if both are diagonal, they commute without any calculation.

Is there such a thing as matrix division?

No. A/B is not used. Multiply by an inverse instead: AX = B gives X = A⁻¹B, and XA = B gives X = BA⁻¹, which are different.

Do the same rules apply to vectors?

Yes. A column vector is an n×1 matrix, so Av is (m×n)(n×1) = m×1, and a row vector is 1×n, so vᵀA is 1×n. The size condition applies exactly as before.

Related guides