Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Multiply Matrices

To multiply AA by BB, the number of columns of AA must equal the number of rows of BB. Each entry of ABAB is one row of AA times one column of BB: multiply matching entries and add.

Recognize the task

Two matrices side by side with no operator between them, or a matrix times a vector: ABAB, AxA\mathbf{x}, (1234)(2013)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\begin{pmatrix} 2 & 0 \\ 1 & 3 \end{pmatrix}, A2=AAA^2 = AA. Test: write the sizes as (m×n)(n×p)(m \times n)(n \times p); the two inner numbers must be equal.
The product is defined in the matrix multiplication lesson; the entry formula is the matrix multiplication formula.

Ways to do it

Row times columnentry by entry
(AB)ij=∑k=1naik bkj(AB)_{ij} = \sum_{k=1}^{n} a_{ik}\, b_{kj}
Each entry is row ii of AA dotted with column jj of BB. The standard way by hand.
Column pictureone column at a time
AB=(Ab1Ab2⋯Abp)AB = \begin{pmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 & \cdots & A\mathbf{b}_p \end{pmatrix}
Column jj of ABAB is AA times column jj of BB, a combination of the columns of AA. Best for a matrix times a vector.
Row pictureone row at a time
rowi(AB)=rowi(A) B\text{row}_i(AB) = \text{row}_i(A)\, B
Row ii of ABAB is row ii of AA times BB, a combination of the rows of BB (see column and row interpretations).

Steps

StepOn (1234)(2013)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\begin{pmatrix} 2 & 0 \\ 1 & 3 \end{pmatrix}
1Write both sizes and compare the inner numbers. Columns of AA must equal rows of BB. If they differ, the product does not exist.(2×2)(2×2)(2 \times 2)(2 \times 2): inner 2=22 = 2 ✓
2Read off the size of the product. The outer numbers: rows of AA by columns of BB.ABAB is 2×22 \times 2
3Compute row 1: row 1 of A times each column of B. Multiply matching entries and add.c11=1⋅2+2⋅1=4c_{11} = 1 \cdot 2 + 2 \cdot 1 = 4, c12=1⋅0+2⋅3=6c_{12} = 1 \cdot 0 + 2 \cdot 3 = 6
4Repeat for every other row. An m×pm \times p product has mpmp entries, each one row times one column.c21=3⋅2+4⋅1=10c_{21} = 3 \cdot 2 + 4 \cdot 1 = 10, c22=3⋅0+4⋅3=12c_{22} = 3 \cdot 0 + 4 \cdot 3 = 12
5Assemble the matrix and keep the order. ABAB and BABA are usually different (non-commutativity).AB=(461012)AB = \begin{pmatrix} 4 & 6 \\ 10 & 12 \end{pmatrix}, while BA=(241014)BA = \begin{pmatrix} 2 & 4 \\ 10 & 14 \end{pmatrix}

Worked examples

Example 1 · two 2×2 matrices

basic
(2103)(142−1)\begin{pmatrix} 2 & 1 \\ 0 & 3 \end{pmatrix}\begin{pmatrix} 1 & 4 \\ 2 & -1 \end{pmatrix}
sizes (2×2)(2×2)(2 \times 2)(2 \times 2)
row 1: 2⋅1+1⋅2=42 \cdot 1 + 1 \cdot 2 = 4, 2⋅4+1⋅(−1)=72 \cdot 4 + 1 \cdot (-1) = 7
row 1 times each column
row 2: 0⋅1+3⋅2=60 \cdot 1 + 3 \cdot 2 = 6, 0⋅4+3⋅(−1)=−30 \cdot 4 + 3 \cdot (-1) = -3
(476−3)\begin{pmatrix} 4 & 7 \\ 6 & -3 \end{pmatrix}

Example 2 · different shapes

2×3 times 3×2
(102−131)(312110)\begin{pmatrix} 1 & 0 & 2 \\ -1 & 3 & 1 \end{pmatrix}\begin{pmatrix} 3 & 1 \\ 2 & 1 \\ 1 & 0 \end{pmatrix}
inner 3=33 = 3, result 2×22 \times 2
c11=3+0+2=5c_{11} = 3 + 0 + 2 = 5, c12=1+0+0=1c_{12} = 1 + 0 + 0 = 1
c21=−3+6+1=4c_{21} = -3 + 6 + 1 = 4, c22=−1+3+0=2c_{22} = -1 + 3 + 0 = 2
(5142)\begin{pmatrix} 5 & 1 \\ 4 & 2 \end{pmatrix}
the reverse order would be 3×33 \times 3

Example 3 · matrix times vector

column picture
(2−10134)(312)\begin{pmatrix} 2 & -1 & 0 \\ 1 & 3 & 4 \end{pmatrix}\begin{pmatrix} 3 \\ 1 \\ 2 \end{pmatrix}
(2×3)(3×1)(2 \times 3)(3 \times 1)
=3(21)+1(−13)+2(04)= 3\begin{pmatrix} 2 \\ 1 \end{pmatrix} + 1\begin{pmatrix} -1 \\ 3 \end{pmatrix} + 2\begin{pmatrix} 0 \\ 4 \end{pmatrix}
vector entries weight the columns
=(514)= \begin{pmatrix} 5 \\ 14 \end{pmatrix}
Multiply your own matrices in the matrix calculator.

See it happen

Matrix A×
Matrix B×
✓ Valid multiplication: A(3×2) × B(2×6) = Result(3×6)
A 3×2
×
B 2×6
=
Result 3×6

For these sizes

  • A has 2 columns and B has 2 rows. They are equal, so A and B can be multiplied.
  • The result takes 3 rows from A and 6 columns from B, so it is 3×6.
  • Click a result cell to see which row of A and which column of B it uses.
Step 1 in action: set the two sizes and see whether the inner numbers match and what size the product will be. Each entry of ABAB comes from one row of AA meeting one column of BB: lay the row along the column, multiply the pairs, add. The rows and columns visualizer highlights the row and column behind every entry, and the AB versus BA tool shows why the order matters: ABAB means "do BB first, then AA".

Common mistakes

Multiplying entry by entry

✗ (1234)(2013)=(20312)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\begin{pmatrix} 2 & 0 \\ 1 & 3 \end{pmatrix} = \begin{pmatrix} 2 & 0 \\ 3 & 12 \end{pmatrix}
✓ row times column: (461012)\begin{pmatrix} 4 & 6 \\ 10 & 12 \end{pmatrix}
The entrywise product is the Hadamard product, a different operation.

Assuming the order does not matter

✗ AB=BAAB = BA
✓ AB=(461012)≠BA=(241014)AB = \begin{pmatrix} 4 & 6 \\ 10 & 12 \end{pmatrix} \neq BA = \begin{pmatrix} 2 & 4 \\ 10 & 14 \end{pmatrix}

Multiplying incompatible sizes

✗ (2×3)(2×3)(2 \times 3)(2 \times 3) multiplied anyway
✓ inner numbers 3≠23 \neq 2: the product is undefined

Wrong size for the result

✗ (2×3)(3×2)(2 \times 3)(3 \times 2) gives a 3×33 \times 3 matrix
✓ the outer numbers give the size: 2×22 \times 2