Guides6 min
Matrix Multiplication: Rules, Worked Examples and Why AB ≠ BA
Matrix multiplication is not entry-by-entry multiplication. You pair each row of the first matrix with each column of the second, multiply and add, which is easy to get wrong at first. This guide covers everything in order, from the size condition to worked examples.
When can two matrices be multiplied?
If A is an m×n matrix and B is an n×p matrix, the product AB exists and is an m×p matrix. The number of columns of A must equal the number of rows of B. A handy way to remember it: the inner numbers must match, and the outer numbers give the size of the result.
For example, a 2×3 matrix times a 3×2 matrix gives a 2×2 matrix, while a 2×3 matrix times another 2×3 matrix is not defined.
How to compute each entry
The entry in row i, column j of the result is the sum of the products of row i of A and column j of B, taken in order. You can think of it as the dot product of the two vectors.
Example: a 2×3 matrix times a 3×2 matrix
A is 2×3 and B is 3×2, so the product exists and is 2×2. Let's compute the entries one at a time.
Changing the order changes the result
With the same two matrices, BA is a 3×3 matrix because B is 3×2 and A is 2×3. The sizes alone are different, so AB and BA cannot even be compared.
Even when both matrices are square, so that both products exist, usually AB ≠ BA.
Multiplying on the left and multiplying on the right are different operations. That is why, when you say "multiply A by B", it matters which side B goes on.
Useful properties
- Associative: (AB)C = A(BC)
- Distributive: A(B + C) = AB + AC, (A + B)C = AC + BC
- Scalars: (kA)B = k(AB) = A(kB)
- Identity: AI = IA = A. The identity matrix plays the role of the number 1 in multiplication.
- Transpose: (AB)ᵀ = BᵀAᵀ. Note that the order flips.
Where matrices behave differently from numbers
- No commutative law. In general AB ≠ BA.
- AB = 0 does not force A = 0 or B = 0. Neither matrix below is the zero matrix, yet their product is.
- No cancellation. AB = AC does not imply B = C. Only when A is invertible can you multiply both sides by A⁻¹ to get B = C.
Common mistakes
- Multiplying entries in the same position. That is a different operation called the Hadamard product, not matrix multiplication.
- Starting to compute without checking sizes. Before multiplying, check that the two inner numbers match.
- Pairing rows and columns the wrong way round. Take rows from A and columns from B.
- Writing (AB)ᵀ as AᵀBᵀ. The order flips: BᵀAᵀ is correct.
FAQ
Can AB exist while BA does not?
Yes. If A is 2×3 and B is 3×3, then AB is a 2×3 matrix, but BA is undefined because B has 3 columns and A has 2 rows.
When multiplying several matrices, does it matter which product I compute first?
No. Multiplication is associative, so any grouping gives the same result. What you cannot do is change the order. Starting with the pair whose sizes fit best often saves intermediate work.
What about multiplying a square matrix by itself several times?
AA is written A². A² is defined only when A is square. Diagonal matrices are easy: just raise each diagonal entry to the power.
Related guides