Home›Courses›Linear Algebra›Notes · Matrix Multiplication
← Lecture 6
Jump toWhy It Matters·The Dot Product·The Size Rule·How To Multiply·Worked Examples·Not Commutative·The Identity·Properties·Surprises·Powers·Systems·Practice
MATH-120 · Linear Algebra · Supplementary NotesJune 2026

Matrix Multiplication

The one operation that powers all of linear algebra — built from scratch, the way it finally clicks

§1Why Matrix Multiplication Is Strange — and Why That's Good

Let me be honest with you up front. When you first see how matrices multiply, your reaction will be: "who on earth invented this, and why so complicated?" You would add matrices entry-by-entry — sensible. You'd expect to multiply them entry-by-entry too. But that's not how it works, and there is a beautiful reason.

🔗
The one-sentence reason
Matrix multiplication is defined the way it is so that it represents doing one transformation after another. If matrix $A$ rotates space and matrix $B$ stretches it, then $AB$ is the single matrix that "stretches, then rotates." Multiplication is composition of actions. Once you see that, the strange rule becomes the only rule that could possibly work.

So forget memorising for a moment. We are going to build the operation from one tiny tool you already know — the dot product — and by the end it will feel inevitable. Stay with me.

§2The Building Block — the Dot Product

Everything in matrix multiplication is built from one simple move: take two equal-length lists of numbers, multiply them position-by-position, and add up the results.

Dot product

The dot product of two lists of the same length, $(a_1, a_2, \dots, a_n)$ and $(b_1, b_2, \dots, b_n)$, is the single number $a_1 b_1 + a_2 b_2 + \cdots + a_n b_n.$

Example 1A dot product in action

$(1, 2, 3) \cdot (4, 5, 6) = (1)(4) + (2)(5) + (3)(6) = 4 + 10 + 18 = 32.$

One row, one column, one number out. Hold onto this — it is the atom of everything that follows.

🎯
The mental picture
A matrix product is nothing more than a whole grid of dot products. Each entry of the answer is one row of the first matrix dotted with one column of the second. That's it. The only thing you must get right is which row meets which column.

§3The Size Rule — When Can You Even Multiply?

Before multiplying, you must check the sizes line up. Unlike addition (which needs identical sizes), multiplication has its own rule — and it is the first thing to check every single time.

The size rule

You can form the product $AB$ only when the number of columns of $A$ equals the number of rows of $B$. If $A$ is $m\times n$ and $B$ is $n\times p$, then $AB$ exists and has size $m\times p$.

A(m×n)·B(n×p)=AB(m×p)

The two inner numbers must match — they "touch and cancel." The two outer numbers give the size of the answer.

🧠
The trick to never forget it
Write the two sizes next to each other: $(m \times n)(n \times p)$. The inner pair must match — that's the requirement. The outer pair becomes the answer's size. Inner numbers shake hands and disappear; outer numbers survive.
Example 2Reading the size rule

(a) $A$ is $2\times3$, $B$ is $3\times4$. Inner: $3 = 3$ ✓. Product $AB$ is $2\times4$.

(b) $A$ is $2\times3$, $B$ is $2\times3$. Inner: $3 \neq 2$. The product $AB$ does not exist.

(c) $A$ is $3\times1$ (a column), $B$ is $1\times3$ (a row). Inner: $1 = 1$ ✓. Product is $3\times3$ — a full matrix from a column times a row!

§4How To Actually Multiply — Row Meets Column

The product AB, entry by entry

The entry in row $i$, column $j$ of $AB$ is the dot product of row $i$ of $A$ with column $j$ of $B$. In symbols, if $A=[a_{ik}]$ and $B=[b_{kj}]$, then $(AB)_{ij} = \sum_{k} a_{ik}\, b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}.$

Here is the rhythm to say in your head: "row $i$ of $A$, column $j$ of $B$ — multiply across, add up, drop it in slot $(i,j)$." Play with the demo below: choose any row of $A$ and any column of $B$, and watch exactly which dot product produces which entry.

Interactive · Pick a row of A and a column of B to see where each entry of AB comes from
A (2×3) — pick a row
123
456
B (3×2) — pick a column
7
9
11
8
10
12
(1, 2, 3) · (7, 9, 11) = 1·7 + 2·9 + 3·11 = 58

This number lands in row 1, column 1 of the product AB. Every entry of AB is one row·column dot product.

§5Worked Examples — From Easy to Confident

Example 3The full 2×2 product, slot by slot

Compute $AB$ for $A = \begin{bmatrix}1&2\\3&4\end{bmatrix}$, $B = \begin{bmatrix}5&6\\7&8\end{bmatrix}$.

Work each of the four slots as a row·column dot product:

$(1,1)$: row 1 · col 1 $= (1)(5)+(2)(7) = 5+14 = 19$.

$(1,2)$: row 1 · col 2 $= (1)(6)+(2)(8) = 6+16 = 22$.

$(2,1)$: row 2 · col 1 $= (3)(5)+(4)(7) = 15+28 = 43$.

$(2,2)$: row 2 · col 2 $= (3)(6)+(4)(8) = 18+32 = 50$.

$$AB = \begin{bmatrix}19 & 22\\43 & 50\end{bmatrix}.$$

Example 4Matrix times a vector

A column vector is just a matrix with one column, so the same rule applies. Compute $\begin{bmatrix}2&1\\1&3\end{bmatrix}\begin{bmatrix}4\\5\end{bmatrix}$.

Row 1 · the column $= (2)(4)+(1)(5) = 8+5 = 13$.

Row 2 · the column $= (1)(4)+(3)(5) = 4+15 = 19$.

$$\begin{bmatrix}2&1\\1&3\end{bmatrix}\begin{bmatrix}4\\5\end{bmatrix} = \begin{bmatrix}13\\19\end{bmatrix}.$$

Notice $(2\times2)(2\times1) = (2\times1)$ — a vector in, a vector out. This is the view of a matrix as a machine that transforms vectors.

★ 5A non-square product — mind the sizes

Compute $CD$ for $C = \begin{bmatrix}1&2&3\\4&5&6\end{bmatrix}$ $(2\times3)$ and $D = \begin{bmatrix}7&8\\9&10\\11&12\end{bmatrix}$ $(3\times2)$.

Inner numbers $3 = 3$ ✓, so $CD$ exists and is $2\times2$. Each entry dots a length-3 row with a length-3 column:

$(1,1) = (1)(7)+(2)(9)+(3)(11) = 7+18+33 = 58.$

$(1,2) = (1)(8)+(2)(10)+(3)(12) = 8+20+36 = 64.$

$(2,1) = (4)(7)+(5)(9)+(6)(11) = 28+45+66 = 139.$

$(2,2) = (4)(8)+(5)(10)+(6)(12) = 32+50+72 = 154.$

$$CD = \begin{bmatrix}58 & 64\\139 & 154\end{bmatrix}.$$

§6The Big Warning — Order Matters

⚠️ AB is usually NOT equal to BA

With ordinary numbers, $5 \times 3 = 3 \times 5$. With matrices this fails. In general $AB \neq BA$. Matrix multiplication is not commutative. The order you multiply in changes the answer — sometimes it even changes whether the product exists at all.

Example 6See it with your own eyes

Take the same $A = \begin{bmatrix}1&2\\3&4\end{bmatrix}$ and $B = \begin{bmatrix}5&6\\7&8\end{bmatrix}$. We found $AB = \begin{bmatrix}19&22\\43&50\end{bmatrix}$. Now compute $BA$:

$(1,1) = (5)(1)+(6)(3) = 5+18 = 23.$

$(1,2) = (5)(2)+(6)(4) = 10+24 = 34.$

$(2,1) = (7)(1)+(8)(3) = 7+24 = 31.$

$(2,2) = (7)(2)+(8)(4) = 14+32 = 46.$

$$BA = \begin{bmatrix}23 & 34\\31 & 46\end{bmatrix} \neq \begin{bmatrix}19 & 22\\43 & 50\end{bmatrix} = AB.$$

Same two matrices, completely different products. This is why we always say "$A$ times $B$" carefully, and why we distinguish left-multiply from right-multiply.

🚫
The consequence — you cannot 'cancel'
Because order matters, you cannot cancel matrices like numbers. From $AB = AC$ you cannot conclude $B = C$. From $AB = CB$ you cannot conclude $A = C$. A matrix does not simply "divide out." Whenever you want to undo a matrix, you must multiply by its inverse on the correct side — left or right, and consistently on both sides of the equation.

§7The Identity Matrix — Multiplication's "1"

Identity matrix

The identity matrix $I_n$ is the $n\times n$ matrix with $1$s on the main diagonal and $0$s everywhere else. For example $I_2 = \begin{bmatrix}1&0\\0&1\end{bmatrix}$ and $I_3 = \begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}.$

The identity earns its name: multiplying by it changes nothing, exactly like the number $1$.

The identity does nothing

For any $m\times n$ matrix $A$, we have $I_m A = A$ and $A I_n = A$. Multiplying by the identity (on either side, with the matching size) returns $A$ unchanged.

Example 7The identity in action

Let $A = \begin{bmatrix}3&1\\2&5\end{bmatrix}$. Then

$$AI = \begin{bmatrix}3&1\\2&5\end{bmatrix}\begin{bmatrix}1&0\\0&1\end{bmatrix} = \begin{bmatrix}3&1\\2&5\end{bmatrix} = A,$$

and $IA = A$ as well. This is the matrix we are chasing when we look for an inverse: $A^{-1}A = I$ means "$A^{-1}$ undoes $A$ back to the do-nothing matrix."

§8The Laws That Still Hold

Multiplication loses commutativity — but it keeps most other good behaviour. Here are the laws you may rely on (assuming all sizes line up so the products exist).

Properties of matrix multiplication
  1. Associative: $A(BC) = (AB)C$. You may regroup, just never reorder.
  2. Left distributive: $A(B + C) = AB + AC$.
  3. Right distributive: $(B + C)A = BA + CA$.
  4. Scalars slide: $k(AB) = (kA)B = A(kB)$ for any scalar $k$.
  5. Identity: $IA = A$ and $AI = A$.
  6. Transpose reverses order: $(AB)^{\mathsf{T}} = B^{\mathsf{T}} A^{\mathsf{T}}$.
🔁
Why the transpose flips the order
Property 6 surprises everyone: $(AB)^{\mathsf{T}} = B^{\mathsf{T}}A^{\mathsf{T}}$, not $A^{\mathsf{T}}B^{\mathsf{T}}$. Think of putting on socks then shoes: to reverse it, you take off shoes first, then socks. Reversing a sequence reverses the order. The same logic governs inverses: $(AB)^{-1} = B^{-1}A^{-1}$.
★ 8Checking associativity

Let $A = \begin{bmatrix}1&2\\0&1\end{bmatrix}$, $B = \begin{bmatrix}2&0\\1&3\end{bmatrix}$, $C = \begin{bmatrix}1&1\\2&0\end{bmatrix}$.

§9Three Surprises That Trip Everyone Up

Matrix multiplication breaks a few "rules" you've trusted since school. Knowing these in advance saves you from confident mistakes.

😮
Surprise 1 — a product can be zero without either factor being zero
With numbers, if $xy = 0$ then $x = 0$ or $y = 0$. Matrices break this. Take $A = \begin{bmatrix}1&0\\0&0\end{bmatrix}$ and $B = \begin{bmatrix}0&0\\0&1\end{bmatrix}$. Neither is the zero matrix, yet $AB = \begin{bmatrix}0&0\\0&0\end{bmatrix} = 0$. So $AB = 0$ does not let you conclude $A=0$ or $B=0$.
😮
Surprise 2 — you can't always square a matrix
To form $A^2 = A \cdot A$, the size rule demands the columns of $A$ match the rows of $A$ — that needs $A$ to be square. A $2\times3$ matrix cannot be squared. But $A A^{\mathsf{T}}$ (size $m\times m$) and $A^{\mathsf{T}}A$ (size $n\times n$) are always defined — the transpose fixes the sizes so a product exists. This is one reason the transpose is so useful in practice.
😮
Surprise 3 — (A+B)² is not A² + 2AB + B²
Expanding $(A+B)^2 = (A+B)(A+B) = A^2 + AB + BA + B^2$. You cannot combine $AB + BA$ into $2AB$ unless $A$ and $B$ happen to commute. So the familiar algebra identity quietly fails. Always expand matrix products in full and respect the order.

§10Powers of a Square Matrix

Matrix powers

For a square matrix $A$, we define $A^2 = AA$, $A^3 = AAA$, and in general $A^k = A \cdot A \cdots A$ ($k$ times). By convention $A^0 = I$. Powers are only defined for square matrices, because only then does $A\cdot A$ satisfy the size rule.

Example 9Computing a power

Let $A = \begin{bmatrix}1&1\\0&1\end{bmatrix}$. Find $A^3$.

$A^2 = \begin{bmatrix}1&1\\0&1\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} = \begin{bmatrix}1&2\\0&1\end{bmatrix}.$

$A^3 = A^2 A = \begin{bmatrix}1&2\\0&1\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} = \begin{bmatrix}1&3\\0&1\end{bmatrix}.$

A clean pattern emerges: $A^k = \begin{bmatrix}1&k\\0&1\end{bmatrix}$. Matrix powers often reveal patterns like this — they are the engine behind modelling repeated processes (population growth, web-page ranking, and more).

§11The Payoff — Systems Become a Single Equation

Here is where all of this pays off, and it connects straight back to everything you solved in Week 1. A whole system of linear equations collapses into one tidy matrix product.

Example 10A system in matrix form

The system $\begin{cases}2x + y = 5 \\ x + 3y = 10\end{cases}$ can be written as $A\mathbf{x} = \mathbf{b}$:

$$\underbrace{\begin{bmatrix}2&1\\1&3\end{bmatrix}}_{A}\underbrace{\begin{bmatrix}x\\y\end{bmatrix}}_{\mathbf{x}} = \underbrace{\begin{bmatrix}5\\10\end{bmatrix}}_{\mathbf{b}}.$$

Multiply out the left side using the row·column rule: row 1 gives $2x + y$, row 2 gives $x + 3y$. Setting these equal to $\mathbf{b}$ reproduces the original two equations exactly. The matrix product is the system.

And now the connection to Lecture 6: if $A$ is invertible, the solution is simply $\mathbf{x} = A^{-1}\mathbf{b}$. (Here the answer is $x = 1$, $y = 3$.) The inverse and multiplication are two halves of the same machine.

🌍
Where this shows up
This single idea — "a matrix times a vector packages a whole linear transformation" — is the foundation of computer graphics (every rotation of a 3D game character is a matrix product), Google's original PageRank algorithm, neural networks (each layer is a matrix multiply), economics, and quantum mechanics. The strange rule you just learned runs an enormous share of the modern world.

§12Practice — Test Yourself

Example P1Compute the product

Find $AB$ where $A = \begin{bmatrix}2&0\\-1&3\end{bmatrix}$, $B = \begin{bmatrix}1&4\\2&-1\end{bmatrix}$.

Example P2Does the product exist?

$A$ is $4\times2$ and $B$ is $4\times2$. (a) Does $AB$ exist? (b) Does $A^{\mathsf{T}}B$ exist, and what size?

★ P3Show order matters

For $A = \begin{bmatrix}0&1\\0&0\end{bmatrix}$ and $B = \begin{bmatrix}0&0\\1&0\end{bmatrix}$, compute $AB$ and $BA$ and compare.

The whole lecture in five lines
  • Every entry of $AB$ is one row of $A$ dotted with one column of $B$.
  • The product exists only when columns of $A$ = rows of $B$; the answer is $(\text{rows of }A)\times(\text{cols of }B)$.
  • Order matters: $AB \neq BA$ in general, so you can never "cancel" a matrix.
  • The identity $I$ does nothing; the inverse $A^{-1}$ undoes $A$ back to $I$.
  • Multiplication is composition of transformations — that's why it's defined this way.

Bring any leftover questions to the tutorial or to TA office hours — and welcome back to Lecture 6, where this all pays off in the inverse.

Supplementary notes — complete
MATH-120 · Shoaib Khan · LUMS · June 2026
← Back to Lecture 6: The Inverse