Linear Algebra · Matrix Multiplication

Matrix Multiplication — Why It Works the Way It Does

Matrix multiplication is not just element-by-element scaling, it is the composition of two linear transformations. Understanding the dot-product definition, the conformability rule, and why AB ≠ BA in general unlocks every deeper result in linear algebra.

Share this page

§ 01Conformability — When Can You Multiply?

Before you can multiply two matrices, you must check that their dimensions are compatible. This is the single most common source of errors for students new to linear algebra.

If A is an m × k matrix and B is a k × n matrix, then the product AB is defined and produces an m × n matrix. The inner dimensions must match, A has k columns and B has k rows.

The Conformability Rule
A (m×k) · B (k×n) = AB (m×n)

Inner dimensions must be equal. Outer dimensions give the shape of the result.

A useful memory trick: write the two size pairs side by side, (m × k) · (k × n). The bold inner values must match; they "cancel", leaving (m × n) as the result size.

A sizeB sizeAB defined?Result size
2 × 33 × 4✓ Yes2 × 4
3 × 22 × 5✓ Yes3 × 5
4 × 44 × 4✓ Yes4 × 4
2 × 34 × 2✗ No— (3 ≠ 4)
1 × 55 × 1✓ Yes1 × 1 (scalar)
5 × 11 × 5✓ Yes5 × 5
Watch out: AB ≠ BA even when both are defined Even if both AB and BA are defined (which requires A and B to be square matrices of the same size), the results are almost never equal. Matrix multiplication is not commutative. This is addressed in depth in § 04.

§ 02The Formula — (AB)ᵢⱼ = Row i · Column j

Each entry of the product matrix is computed as the dot product of a row from A with a column from B. Specifically:

Definition of Matrix Multiplication
(AB)ᵢⱼ = Σₗ Aᵢₗ · Bₗⱼ = aᵢ₁b₁ⱼ + aᵢ₂b₂ⱼ + … + aᵢₖbₖⱼ

Entry (i, j) of AB = the dot product of row i of A with column j of B.

To compute the entry in position (i, j) of the product:

  1. Take row i of A as a list of numbers.
  2. Take column j of B as a list of numbers.
  3. Multiply corresponding entries together and sum them all up.

This must be done for every position (i, j) in the result matrix: that's m × n dot products in total, each of length k.

Example 12 × 2 product — building every entry step by step

Compute AB where:

A = [
12 34
] B = [
56 78
]
  1. (AB)₁₁: Row 1 of A = [1, 2], Col 1 of B = [5, 7]. Dot product: 1·5 + 2·7 = 5 + 14 = 19
  2. (AB)₁₂: Row 1 of A = [1, 2], Col 2 of B = [6, 8]. Dot product: 1·6 + 2·8 = 6 + 16 = 22
  3. (AB)₂₁: Row 2 of A = [3, 4], Col 1 of B = [5, 7]. Dot product: 3·5 + 4·7 = 15 + 28 = 43
  4. (AB)₂₂: Row 2 of A = [3, 4], Col 2 of B = [6, 8]. Dot product: 3·6 + 4·8 = 18 + 32 = 50
AB = [
1922 4350
]
Example 22 × 3 times 3 × 2 — rectangular matrices

Compute AB where A is 2 × 3 and B is 3 × 2. Result will be 2 × 2.

A = [
201 13-1
] B = [
12 40 -13
]
  1. (AB)₁₁ = 2(1) + 0(4) + 1(−1) = 2 + 0 − 1 = 1
  2. (AB)₁₂ = 2(2) + 0(0) + 1(3) = 4 + 0 + 3 = 7
  3. (AB)₂₁ = 1(1) + 3(4) + (−1)(−1) = 1 + 12 + 1 = 14
  4. (AB)₂₂ = 1(2) + 3(0) + (−1)(3) = 2 + 0 − 3 = −1
AB = [
17 14−1
]

§ 03Why AB ≠ BA — Non-Commutativity

One of the most important (and surprising) facts in linear algebra is that matrix multiplication is not commutative. The order matters enormously. There are three distinct ways this can go wrong:

Case 1
AB is defined, BA is not

If A is 2×3 and B is 3×4, then AB is 2×4. But BA would require (3×4)(2×3): inner dims 4 ≠ 2, so BA is undefined.

Case 2
Both defined, different sizes

If A is 2×3 and B is 3×2, then AB is 2×2 and BA is 3×3. They cannot be equal because they have different shapes.

Case 3
Same size, but still unequal

Even for square matrices of the same size, AB and BA are almost never equal. See Example 3 below for a concrete demonstration.

Exception
When AB = BA (commuting matrices)

AB = BA when one matrix is a scalar multiple of I, when both are diagonal, or in special structured cases. These are the exception, not the rule.

Example 3Proving AB ≠ BA for 2×2 matrices

Let A and B be:

A = [
12 01
] B = [
10 31
]
  1. Compute AB: (1·1+2·3, 1·0+2·1) = (7, 2) and (0·1+1·3, 0·0+1·1) = (3, 1).
  2. Compute BA: (1·1+0·0, 1·2+0·1) = (1, 2) and (3·1+1·0, 3·2+1·1) = (3, 7).
AB = [
72 31
] BA = [
12 37
]
AB ≠ BA — the (1,1) entries alone are 7 vs. 1. Always respect the order of multiplication.

§ 04The Identity Matrix — The Matrix "1"

The identity matrix Iₙ is the n×n matrix with 1s on the main diagonal and 0s everywhere else. It plays the role of the number 1 in ordinary multiplication:

Identity Matrix Property
AI = IA = A (for any square matrix A)

More generally, if A is m×n, then A·Iₙ = A and Iₘ·A = A.

I₂ = [
10 01
] I₃ = [
100 010 001
]
Example 4Verifying AI = A

Let A be the 2×2 matrix from Example 1. Verify that AI₂ = A.

  1. Row 1 of A · Col 1 of I₂: [1,2]·[1,0]ᵀ = 1·1 + 2·0 = 1 ✓
  2. Row 1 of A · Col 2 of I₂: [1,2]·[0,1]ᵀ = 1·0 + 2·1 = 2 ✓
  3. Row 2 of A · Col 1 of I₂: [3,4]·[1,0]ᵀ = 3 ✓
  4. Row 2 of A · Col 2 of I₂: [3,4]·[0,1]ᵀ = 4 ✓
AI₂ = A, as expected. The identity preserves every row unchanged.

Matrix Powers

For a square matrix A, matrix powers are defined by repeated multiplication: A² = AA, A³ = AAA, and so on. A⁰ = I by convention. Powers obey the usual index laws: AᵐAⁿ = Aᵐ⁺ⁿ. However, (AB)² ≠ A²B² in general, since (AB)² = ABAB, not AABB.

Example 5Computing A² for a 2×2 matrix

Find A² where A = [[2, 1], [1, 3]].

  1. (A²)₁₁ = 2·2 + 1·1 = 5
  2. (A²)₁₂ = 2·1 + 1·3 = 5
  3. (A²)₂₁ = 1·2 + 3·1 = 5
  4. (A²)₂₂ = 1·1 + 3·3 = 10
A² = [[5, 5], [5, 10]]

§ 05Algebraic Properties of Matrix Multiplication

While commutativity fails, most other familiar algebraic laws do hold. These properties allow matrices to be manipulated in proofs and computations with confidence.

PropertyFormulaNote
Associativity(AB)C = A(BC)Always true — multiplication order is preserved
Distributivity (left)A(B + C) = AB + ACMatrix addition distributes over multiplication
Distributivity (right)(A + B)C = AC + BCBoth sides must be considered separately
Scalar multiplicationc(AB) = (cA)B = A(cB)Scalar factors can move freely
Transpose of product(AB)ᵀ = BᵀAᵀOrder reverses when taking transpose
IdentityAI = IA = AIdentity matrix acts like the number 1
Zero matrixA·0 = 0·A = 0The zero matrix annihilates everything
The Transpose Reversal Rule is Critical (AB)ᵀ = BᵀAᵀ, NOT AᵀBᵀ. This reversal happens because transposing swaps rows and columns, which effectively reverses the order of the multiplication. This fact is essential in proving identities about symmetric and orthogonal matrices.
Example 6Verifying (AB)ᵀ = BᵀAᵀ

Using A = [[1,2],[3,4]] and B = [[5,6],[7,8]] from Example 1, where AB = [[19,22],[43,50]].

  1. (AB)ᵀ = [[19,43],[22,50]]
  2. Bᵀ = [[5,7],[6,8]], Aᵀ = [[1,3],[2,4]]
  3. BᵀAᵀ: (1,1) = 5·1+7·2 = 19; (1,2) = 5·3+7·4 = 43; (2,1) = 6·1+8·2 = 22; (2,2) = 6·3+8·4 = 50
  4. BᵀAᵀ = [[19,43],[22,50]] = (AB)ᵀ ✓
The reversal rule (AB)ᵀ = BᵀAᵀ is confirmed.

§ 06More Worked Examples

Example 73 × 3 matrix product

Compute AB where A = [[1,0,2],[0,3,0],[4,0,1]] and B = [[1,1,0],[2,0,1],[0,3,1]].

  1. Row 1 of A = [1,0,2]: (AB)₁₁ = 1+0+0 = 1; (AB)₁₂ = 1+0+6 = 7; (AB)₁₃ = 0+0+2 = 2
  2. Row 2 of A = [0,3,0]: (AB)₂₁ = 0+6+0 = 6; (AB)₂₂ = 0+0+0 = 0; (AB)₂₃ = 0+3+0 = 3
  3. Row 3 of A = [4,0,1]: (AB)₃₁ = 4+0+0 = 4; (AB)₃₂ = 4+0+3 = 7; (AB)₃₃ = 0+0+1 = 1
AB = [[1,7,2],[6,0,3],[4,7,1]]
Example 8Matrix–vector product as a linear combination of columns

The product Ax, where x is a column vector, equals a linear combination of the columns of A, with the entries of x as coefficients. This is a fundamental geometric view of matrix multiplication.

Let A = [[1,3],[2,4]] and x = [2, −1]ᵀ.

  1. Standard approach: (1·2+3·(−1), 2·2+4·(−1)) = (−1, 0).
  2. Column view: Ax = 2·[1,2]ᵀ + (−1)·[3,4]ᵀ = [2,4]ᵀ + [−3,−4]ᵀ = [−1, 0]ᵀ. Same answer.
Ax = [−1, 0]ᵀ. The column perspective is essential for understanding null spaces and solutions to Ax = b.
Example 9Row vector times matrix — a linear combination of rows

When a row vector yᵀ premultiplies A, the result is a linear combination of the rows of A, with the entries of yᵀ as coefficients.

Let yᵀ = [3, 1] and A = [[2, 5],[1, 0]]. Then yᵀA = 3·[2,5] + 1·[1,0] = [6,15]+[1,0] = [7, 15].

yᵀA = [7, 15]. Every row of the product is a linear combination of rows of A.
Example 10Outer product — column times row

An (m×1) column vector times a (1×n) row vector gives an (m×n) matrix: a rank-1 matrix called the outer product.

Let u = [1, 2, 3]ᵀ (3×1) and vᵀ = [4, 5] (1×2). Then uvᵀ is 3×2.

  1. Row 1: 1·[4,5] = [4, 5]
  2. Row 2: 2·[4,5] = [8, 10]
  3. Row 3: 3·[4,5] = [12, 15]
uvᵀ = [[4,5],[8,10],[12,15]]. Every row is a multiple of vᵀ — the matrix has rank 1.

§ 07Block Matrix Multiplication

Large matrices can be partitioned into smaller blocks (submatrices), and multiplication can be performed block-by-block, exactly as if the blocks were individual entries, provided the block dimensions are conformable.

Block Multiplication Rule
[ A₁₁ A₁₂ ] [ B₁₁ B₁₂ ] [ A₁₁B₁₁+A₁₂B₂₁ A₁₁B₁₂+A₁₂B₂₂ ] [ A₂₁ A₂₂ ] [ B₂₁ B₂₂ ] = [ A₂₁B₁₁+A₂₂B₂₁ A₂₁B₁₂+A₂₂B₂₂ ]

The inner block dimensions must match, just as with ordinary entries.

Block multiplication is especially powerful when some blocks are zero matrices or identity matrices: the product simplifies dramatically without computing every entry. It is also the foundation for many efficient computational algorithms and for the analysis of structured matrices such as block-diagonal or block-triangular matrices.

Example 11Block multiplication with an identity block

Partition A = [[I₂ | C], [0 | D]] and B = [[E], [F]] where I₂ is 2×2 identity and all blocks are conformable.

  1. Top block of AB: I₂·E + C·F = E + CF (the identity block leaves E unchanged).
  2. Bottom block of AB: 0·E + D·F = DF.
AB = [[E + CF], [DF]] — the zero and identity blocks simplify computation considerably.
Example 12When does AB = 0 not imply A = 0 or B = 0?

Unlike ordinary numbers, matrices can satisfy AB = 0 (the zero matrix) with neither A nor B being zero. These are called zero divisors.

Let A = [[1,2],[2,4]] and B = [[2,−4],[−1,2]].

  1. (AB)₁₁ = 1·2+2·(−1) = 0; (AB)₁₂ = 1·(−4)+2·2 = 0
  2. (AB)₂₁ = 2·2+4·(−1) = 0; (AB)₂₂ = 2·(−4)+4·2 = 0
AB = 0 yet A ≠ 0 and B ≠ 0. This happens because det(A) = 4−4 = 0, so A is singular. Zero divisors arise precisely from non-invertible (singular) matrices.
Key Takeaways Before the Quiz Conformability: (m×k)(k×n) = m×n. Entry (i,j) of AB is the dot product of row i of A with column j of B. Multiplication is associative and distributive but NOT commutative. The transpose reverses order: (AB)ᵀ = BᵀAᵀ. Powers: (AB)² = ABAB ≠ A²B². AB = 0 does not imply A or B is zero when matrices are singular.

§ 08Common Mistakes

Mistake 1 — Multiplying entry-by-entry The most common error: computing (AB)ᵢⱼ = Aᵢⱼ · Bᵢⱼ. This is Hadamard (element-wise) multiplication, NOT matrix multiplication. The correct formula requires the full dot product of a row of A with a column of B.
Mistake 2 — Assuming AB = BA Always check whether the order matters. In proofs and equations involving matrix expressions, you cannot casually swap the order of a product. If asked to solve ABx = b, you cannot factor as BAx unless you've verified commutativity.
Mistake 3 — Cancellation: AB = AC does not imply B = C Unlike numbers, you cannot cancel A from AB = AC unless A is invertible. If A is singular, AB and AC can be equal with B ≠ C. Always check invertibility before cancelling.
Mistake 4 — Forgetting to reverse order in (AB)ᵀ Students often write (AB)ᵀ = AᵀBᵀ. The correct rule is (AB)ᵀ = BᵀAᵀ. This extends: (ABC)ᵀ = CᵀBᵀAᵀ, always reversing the full chain.

§ 09Practice Quiz — Matrix Multiplication

0 / 10
Question 1 of 10
If A is a 3 × 4 matrix and B is a 4 × 2 matrix, what are the dimensions of AB?
  1. Conformability: A is (3×4), B is (4×2). Inner dims match (both 4).
  2. Result takes outer dims: 3 × 2.
Question 2 of 10
Compute the (1,2) entry of AB where A = [[2,1],[0,3]] and B = [[1,4],[2,0]].
  1. (AB)₁₂ = Row 1 of A · Col 2 of B = [2,1]·[4,0]ᵀ = 2·4 + 1·0 = 8.
Question 3 of 10
Is AB always equal to BA for square matrices of the same size?
  1. Matrix multiplication is NOT commutative. AB ≠ BA in general.
  2. It holds only in special cases: e.g., when one matrix is a scalar multiple of I, or when both are diagonal.
Question 4 of 10
Let A = [[1,0],[0,2]] and B = [[3,1],[4,2]]. Compute the (2,1) entry of AB.
  1. (AB)₂₁ = Row 2 of A · Col 1 of B = [0,2]·[3,4]ᵀ = 0·3 + 2·4 = 8.
Question 5 of 10
What is the correct formula for the transpose of a product, (AB)ᵀ?
  1. (AB)ᵀ = BᵀAᵀ, the order reverses when taking the transpose of a product.
  2. This generalises: (ABC)ᵀ = CᵀBᵀAᵀ.
Question 6 of 10
Compute the full product AB where A = [[1,2],[3,4]] and B = [[0,1],[1,0]]. Enter the (1,1) entry of AB.
  1. (AB)₁₁ = Row 1·Col 1 = [1,2]·[0,1]ᵀ = 0+2 = 2.
  2. Full product: AB = [[2,1],[4,3]].
Question 7 of 10
If A is a 3×3 matrix, what is A·I₃?
  1. Multiplying any matrix by the identity matrix returns the original matrix: A·I = I·A = A.
Question 8 of 10
Given A = [[1,1],[0,0]] and B = [[1,0],[−1,0]], compute AB. What type of result is it?
  1. (AB)₁₁ = 1·1+1·(−1) = 0; (AB)₁₂ = 1·0+1·0 = 0.
  2. (AB)₂₁ = 0·1+0·(−1) = 0; (AB)₂₂ = 0.
  3. AB = 0 (the zero matrix), yet neither A nor B is zero. This is a zero divisor example.
Question 9 of 10
Matrix multiplication IS associative. Which of the following correctly states this?
  1. Associativity: (AB)C = A(BC). The grouping of multiplications does not matter.
  2. This is different from commutativity (AB = BA), which does NOT hold in general.
Question 10 of 10
For A = [[2,3],[1,4]] and B = [[1,0],[0,1]] (identity), what is the (2,2) entry of AB?
  1. B = I₂, so AB = A. Therefore (AB)₂₂ = A₂₂ = 4.
  2. Alternatively: (AB)₂₂ = Row 2 of A · Col 2 of B = [1,4]·[0,1]ᵀ = 0+4 = 4.
0/10

Keep practising!

Cookie Settings