Search the complete library

What do you want to learn or calculate?

Quick linksAll calculatorsMath subjectsPractice questionsFormula library
← Linear Algebra formulas

Matrix multiplication

Compose two linear transformations by row-column products.

Linear Algebra · Matrices
$$(AB)_{ij}=\sum_{k=1}^{n}a_{ik}b_{kj}$$

Matrix multiplication is one of 5 matrices formulas in the linear algebra section of this library, and it is used at high school · university level.

Why matrix multiplication works

Matrices stand for transformations, and the product stands for doing B first and then A. To find where the j-th input direction ends up you push column j of B through A, and pushing a column through A means dotting it with each row. That is precisely the sum over k written in the formula.

What each symbol means

$A$ is $m\times n$ and $B$ is $n\times p$.

Matrix multiplication: when it holds

The inner dimensions must match; generally $AB\ne BA$.

When it stops applying

The product does not exist unless the number of columns in A matches the number of rows in B, since otherwise a row and a column have different lengths and cannot be paired off. Two 2 by 3 matrices cannot be multiplied in either order.

Matrix multiplication: a worked example

For row $(1,2)$ and column $(3,4)^T$, the entry is $1(3)+2(4)=11$.

The mistake to avoid

What people do: Students multiply the matrices entry by entry, pairing the top-left with the top-left.

Why it goes wrong: That operation exists but represents something else entirely; it does not compose two transformations and it does not respect the way matrices act on vectors.

Do this instead: Use rows against columns: the entry in row i, column j comes from row i of A paired with column j of B. For row (1, 2) and column (3, 4), the entry is 1(3) + 2(4) = 11.

Matrix multiplication: step by step

  1. Name the unknown, and the unit the answer has to come out in.
  2. Match the symbols to your values. $A$ is $m\times n$ and $B$ is $n\times p$.
  3. Check the conditions before substituting. The inner dimensions must match; generally $AB\ne BA$.
  4. Substitute, keep exact values to the last line, then test the sign, size, and unit against a rough estimate — the check that catches most linear algebra slips.

Where this formula fits

Subject
Linear Algebra formulas — 17 entries in this library
Topic
Matrices
Level
High school · University

Formulas are easiest to keep when they sit inside a method rather than on a list. Use the links below to see where matrix multiplication comes from, to check a calculation against a tool, and to practise it until you can recall it without looking.

Questions about matrix multiplication

Is AB the same as BA?

Almost never, and often only one of them is even defined. Take A = [[1, 2], [3, 4]] and B = [[0, 1], [1, 0]]: then AB is [[2, 1], [4, 3]] while BA is [[3, 4], [1, 2]].

What size is the answer?

Rows from the left matrix, columns from the right one. A 4 by 2 times a 2 by 7 gives a 4 by 7, and the matching inner 2s disappear into the sums.

Why does the second matrix act first?

Because of how function notation reads. In ABx the vector x meets B first, so writing AB means apply B, then A, the same right-to-left order as f(g(x)).

Does entry-by-entry multiplication ever get used?

Yes, it is called the Hadamard product and shows up in statistics and neural networks. It is a different operation with a different symbol, and it needs both matrices to be exactly the same shape.

Stuck on a problem?

Work a matrix multiplication problem step by step

Type your own problem, or upload a photo of it. You get the method, the answer, and a check you can repeat yourself.