How to multiply matrices: dimensions and worked examples

To multiply two matrices, we combine a row from the first matrix with a column from the second. The dimensions tell us whether those pairs fit and how large the answer will be. Let’s check that setup, then calculate every entry of a product.

Check the matrix dimensions first

Matrix dimensions are written as rows × columns. If A is m × n and B is n × p, the product AB is defined and has dimensions m × p.

(m×n)(n×p) gives m×p

The number of columns in A must equal the number of rows in B. For example, a 2 × 3 matrix times a 3 × 4 matrix gives a 2 × 4 matrix. Reversing that order gives 3 × 4 times 2 × 3, whose inner dimensions do not match, so that reversed product is undefined.

Example: Multiply two 2 × 2 matrices

A=[263-1]
B=[-4-210]

Both matrices are 2 × 2, so AB is defined and is also 2 × 2. Each entry comes from a row-by-column dot product: multiply the matching components, then add the products.

A row of A multiplied by a column of BA is the matrix with rows 2, 6 and 3, negative 1. B has rows negative 4, negative 2 and 1, 0. The first row of A and first column of B are highlighted. Their dot product is 2 times negative 4 plus 6 times 1, which equals negative 2, the first entry of AB.AB263−1−4−210Row 1Column 12(−4) + 6(1) = −2Entry (1, 1) of AB
A row from the first matrix and a column from the second matrix determine one entry in the product.

For row 1, column 1, use row (2, 6) from A and column (−4, 1) from B.

2(-4)+6(1)=-2

For row 1, column 2, keep the first row of A and use the second column of B.

2(-2)+6(0)=-4

Now use the second row of A for the two entries in the second row of AB.

3(-4)+(-1)(1)=-13
3(-2)+(-1)(0)=-6

Place each result in the row and column that produced it.

AB=[-2-4-13-6]

Why the order matters

Even when both AB and BA are defined, their entries can differ. For these same matrices, reversing the order gives

BA=[-14-2226]

That is a different matrix, so this example shows why matrix multiplication is not commutative. Some matrix pairs do commute, but exchanging the order is not a general multiplication rule.

Multiplying a matrix by a scalar

A scalar is a single number. To multiply a matrix by a scalar, multiply every entry by that number. For example,

3[62-1-4]=[186-3-12]

Associative and distributive properties

When the dimensions permit the operations, matrix multiplication is associative, so we can change the grouping while keeping the order:

(AB)C=A(BC)

It is also distributive:

A(B+C)=AB+AC
(A+B)C=AC+BC

Identity matrices, inverses, and zero matrices

An identity matrix has 1s on its main diagonal and 0s elsewhere. Multiplying by the identity of the appropriate size leaves a matrix unchanged. The 2 × 2 identity is

I2=[1001]

For an m × n matrix A, we have IₘA = A and AIₙ = A. If a square matrix has an inverse A⁻¹, multiplying A and its inverse in either order gives the identity. A square matrix need not have an inverse.

A zero matrix contains only zeros. Multiplying by a zero matrix gives a zero matrix whenever the dimensions make the product defined, with the resulting dimensions determined by the outer sizes as before.