How to Multiply Matrices: A Visual Beginner's Guide

Why matrix multiplication isn't entry-by-entry, how the row-by-column dot product works, and why order matters completely ($A B \ne B A$).

1. Introduction: The Most Common Student Surprise

When students first learn matrix addition, it feels intuitive: you simply add matching cells $(A + B)_{ij} = a_{ij} + b_{ij}$. Naturally, beginners expect matrix multiplication to work the same way—multiplying matching cells together.

However, that entrywise product (known as the Hadamard product) is not what mathematicians and scientists mean by matrix multiplication. True matrix multiplication is based on composing linear functions together. Because of this, it follows a famous mechanical pattern: Row $\times$ Column.

2. Rule #1: The Golden Dimension Compatibility Check

You cannot multiply just any two matrices together. Before touching a single number, you must check their dimensions:

$$(m \times \mathbf{k}) \times (\mathbf{k} \times n) = (m \times n)$$

The inner dimensions must match. That is, the number of columns in the first matrix $A$ must exactly equal the number of rows in the second matrix $B$. If they do not match, the product $AB$ is completely undefined.

The outer dimensions determine the size of the result: multiplying an $m \times k$ matrix by a $k \times n$ matrix produces an $m \times n$ matrix.

3. The Row-by-Column Dot Product Formula

To compute the entry in row $i$ and column $j$ of the product matrix $C = AB$, you take the dot product of the $i$-th row of $A$ with the $j$-th column of $B$:

$$c_{ij} = \sum_{p=1}^k a_{ip} b_{pj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{ik}b_{kj}$$

You traverse across row $i$ of matrix $A$ while simultaneously moving down column $j$ of matrix $B$, multiplying each corresponding pair and summing the results.

Worked Example: $2 \times 2$ Multiplication

Let $A = \begin{bmatrix} 1 & 3 \\ 2 & 4 \end{bmatrix}$ and $B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}$. Both are $2 \times 2$, so their product $C = AB$ is also $2 \times 2$:

  • Entry $c_{11}$ (Row 1 $\cdot$ Col 1): $(1)(5) + (3)(7) = 5 + 21 = 26$
  • Entry $c_{12}$ (Row 1 $\cdot$ Col 2): $(1)(6) + (3)(8) = 6 + 24 = 30$
  • Entry $c_{21}$ (Row 2 $\cdot$ Col 1): $(2)(5) + (4)(7) = 10 + 28 = 38$
  • Entry $c_{22}$ (Row 2 $\cdot$ Col 2): $(2)(6) + (4)(8) = 12 + 32 = 44$
$$C = \begin{bmatrix} 26 & 30 \\ 38 & 44 \end{bmatrix}$$
Advertisement Slot

4. Why Matrix Multiplication is NOT Commutative ($AB \ne BA$)

In scalar arithmetic, order never matters: $3 \times 5 = 5 \times 3 = 15$. But matrix multiplication is non-commutative:

$$A B \ne B A \quad \text{(in general)}$$

Why? Because matrices represent transformations applied in sequence. In real life, order matters: putting on your socks then putting on your shoes is very different from putting on your shoes then putting on your socks!

In geometry, rotating an object $90^\circ$ around the x-axis and then $90^\circ$ around the z-axis leaves the object in a completely different final orientation than performing the z-rotation first.

Try the Interactive Multiplication Calculator

Adjust matrix dimensions from 1 to 6, type fractions or decimals, and view every dot product formula step-by-step.

5. Real-World Application: Artificial Intelligence and Deep Learning

Why is matrix multiplication the single most computationally intensive operation in modern computer science? Because it powers Artificial Intelligence and Large Language Models.

In deep neural networks, every dense layer computes:

$$\mathbf{y} = \sigma(W \mathbf{x} + \mathbf{b})$$

Here, $\mathbf{x}$ is an input vector of features (or word embeddings), $W$ is a giant weight matrix containing millions or billions of trained parameters, and $\mathbf{b}$ is a bias vector.

When ChatGPT or a self-driving car processes an input, the graphics processing unit (GPU) performs trillions of matrix multiplications every single second using dedicated tensor processing cores designed specifically for fast row-by-column dot products.

6. Key Matrix Multiplication Properties

  • Associative: $A(BC) = (AB)C$. You can group products in any order.
  • Distributive: $A(B + C) = AB + AC$ and $(A + B)C = AC + BC$.
  • Identity: $A I = I A = A$ for a square identity matrix $I$.
  • Transpose of a Product: $(AB)^T = B^T A^T$. The order reverses upon transposition!