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.
- 2×3 times 3×4 → 2×4 ✓
- 2×3 times 2×3 → undefined (3 ≠ 2)
- 3×1 times 1×3 → 3×3 ✓, but 1×3 times 3×1 → 1×1 (a single number, the dot product)
So for non-square matrices it is common that AB exists while BA does not.
Rule 2. Multiplication is not commutative: AB ≠ BA
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
- One of them is the identity I or the zero matrix
- One is a power or the inverse of the other: A·A² = A²·A, A·A⁻¹ = A⁻¹·A
- Both are diagonal (the diagonals just multiply entrywise)
- One is a scalar matrix kI
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.
You may move the parentheses, but not the order of A, B and C.
Rule 4. Multiplication distributes over addition
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
- AI = IA = A. The identity plays the role of the number 1.
- A·0 = 0·A = 0. The zero matrix plays the role of 0.
- But AB = 0 does not imply A = 0 or B = 0.
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.
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
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
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)ᵀ = 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²
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
| Rule | Holds? | Note |
|---|---|---|
| Size condition (m×n)(n×p) | required | otherwise 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