linear-algebra

Matrix Multiplication: A Step-by-Step Guide With Worked Examples

How matrix multiplication actually works — dimension rules, the row-times-column recipe, common mistakes, and the link to linear maps.
AI-Math Editorial Team

By AI-Math Editorial Team

Published 2026-05-01

Matrix multiplication is the operation that drives linear algebra, computer graphics, machine learning, and physics simulations. Yet most students learn it as a mechanical recipe and never see why it is defined the way it is. This guide gives you both the recipe and the intuition.

Dimension rule first

Before you compute anything, check dimensions. To multiply ABA \cdot B:

  • AA must have shape m×nm \times n
  • BB must have shape n×pn \times p
  • Result ABAB has shape m×pm \times p

The inner dimensions must match (n=nn = n); the outer dimensions become the result shape.

If you ever try to multiply a 3×43 \times 4 by a 5×25 \times 2, the operation is undefined — no amount of arithmetic will save you.

The row-times-column recipe

The (i,j)(i, j) entry of ABAB is the dot product of row ii of AA with column jj of BB:

(AB)ij=k=1nAikBkj(AB)_{ij} = \sum_{k=1}^{n} A_{ik} B_{kj}

Worked example

A=(1234),B=(5678)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \quad B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}

Compute ABAB:

  • (AB)11=15+27=19(AB)_{11} = 1\cdot 5 + 2\cdot 7 = 19
  • (AB)12=16+28=22(AB)_{12} = 1\cdot 6 + 2\cdot 8 = 22
  • (AB)21=35+47=43(AB)_{21} = 3\cdot 5 + 4\cdot 7 = 43
  • (AB)22=36+48=50(AB)_{22} = 3\cdot 6 + 4\cdot 8 = 50

So AB=(19224350)AB = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}.

Why is multiplication defined this way?

Matrices represent linear maps between vector spaces. If AA maps from Rn\mathbb{R}^n to Rm\mathbb{R}^m, and BB maps from Rp\mathbb{R}^p to Rn\mathbb{R}^n, then ABAB should be the composition of those maps. The row-times-column rule is precisely what produces composition. The recipe is not arbitrary — it falls out of the requirement that ABAB encode "first apply BB, then apply AA".

Properties (and non-properties!)

PropertyHolds?
A(BC)=(AB)CA(BC) = (AB)C associativeYes
A(B+C)=AB+ACA(B + C) = AB + AC distributiveYes
AB=BAAB = BA commutativeNo, in general
AB=0A=0AB = 0 \Rightarrow A = 0 or B=0B = 0No

The non-commutativity is the single biggest mental adjustment from scalar arithmetic.

Common mistakes

  • Adding instead of multiplying the row-column products (you do both — multiply pairwise then sum).
  • Switching the dimension check order — it must be (m×n)(n×p)(m \times n)(n \times p), not (n×m)(n×p)(n \times m)(n \times p).
  • Assuming commutativityABAB may not even be defined if BABA is.

Try with the AI Matrix Solver

Type any pair of matrices into the Matrix Calculator for fully-shown row-by-row work.

Related references:

AI-Math Editorial Team

By AI-Math Editorial Team

Published 2026-05-01

A small team of engineers, mathematicians, and educators behind AI-Math, focused on making step-by-step math help accessible to every student.