MatrixStep

Matrix Multiplication Calculator

Shows how each entry of AB is computed from a row of A and a column of B.

INPUT

Integers, fractions (1/3) and decimals (0.25) are accepted. Empty cells count as 0. Paste a block of numbers from a spreadsheet or textbook into the first cell to fill the whole matrix.

RESULT

LaTeX is the math code you can paste into Overleaf, Notion equation blocks or Word's equation editor.

Rules of matrix multiplication

If A is m×n and B is n×p, then AB is m×p. The entry (AB)ᵢⱼ is the sum of the products of row i of A and column j of B.

Full explanation with examples: How to Multiply Matrices: Rules, Worked Examples and Why AB ≠ BA

Exam tipThe number of columns of A must equal the number of rows of B. In general AB ≠ BA.

How to do it by hand

  1. Check the sizes first. A must be m×n and B must be n×p; then AB is m×p. If the column count of A differs from the row count of B the product is undefined.
  2. Entry (i, j) of the result is row i of A dotted with column j of B: multiply matching entries and add. Trace the row with one finger and the column with the other.
  3. Repeat for every (i, j). Two 2×2 matrices need 4 dot products; two 3×3 need 9.
  4. Order matters. AB and BA are generally different, and one of them may not even be defined.
Worked example

Let A = [1 2; 3 4] and B = [0 1; 1 0]. Compute AB.

(1,1): 1·0 + 2·1 = 2, (1,2): 1·1 + 2·0 = 1

(2,1): 3·0 + 4·1 = 4, (2,2): 3·1 + 4·0 = 3

AB = [2 1; 4 3]. B swaps columns, so the two columns of A traded places.

BA = [3 4; 1 2] swaps the rows instead. You can see AB ≠ BA right away.

Where is it used?

  • Writing a linear system as Ax = b is itself a matrix product. Almost everything in linear algebra starts here.
  • Computer graphics represents rotation, translation and scaling as matrices and multiplies them to combine transforms.
  • One layer of a neural network multiplies the input vector by a weight matrix. Most of deep learning is matrix multiplication.
  • In a Markov chain, repeatedly multiplying by the transition matrix gives the distribution after n steps.

Common mistakes

  • Multiplying matching entries. [1 2; 3 4]·[5 6; 7 8] is not [5 12; 21 32]; you have to dot rows with columns. The right answer is [19 22; 43 50].
  • Assuming AB = BA. Multiplication does not commute, so (A+B)² = A² + 2AB + B² is also wrong. The correct expansion is A² + AB + BA + B².
  • Concluding from AB = 0 that A = 0 or B = 0. Plenty of nonzero matrices multiply to zero.

How to use

  1. Set the matrix size with the row and column buttons. Up to 6×6 is supported.
  2. Type numbers into the cells and the result updates instantly. Enter fractions as 1/3 and negatives as -2.
  3. Enter moves to the next cell; the ← → ↑ ↓ arrow keys move between cells.
  4. Open ‘Steps’ to see the full working. ‘Copy LaTeX’ copies the result as math code you can paste into Overleaf, a Notion equation block or Word's equation editor.

FAQ

Why does the row count of B change automatically?
The product is only defined when the column count of A equals the row count of B, so B follows A.
How do I compute BA?
Swap the matrices you enter as A and B.

Related guides