On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

Math · Algebra Fundamentals · Grade 9-12

Matrix Multiplication

Matrix multiplication forms AB by dotting each row of A with each column of B; an m×n times an n×p gives m×p.

(AB)ij=∑k=1naik⋅bkj

Quick Answer

Matrix multiplication forms AB by dotting each row of A with each column of B; an m×n times an n×p gives m×p. Use it to chain one table of numbers into another: quantities times prices, one transformation followed by another, or the coefficients of a system times its unknowns. Before multiplying, check that the number of columns of A equals the number of rows of B; otherwise AB does not exist. Order matters, so AB and BA are usually different.

Why This Matters

Matrix multiplication packs many separate sums of products into one operation: order quantities times unit prices give every customer's bill at once, and a whole system of equations becomes the single statement Ax=b. Rotations and stretches combine by multiplying their matrices. Treating it like ordinary multiplication causes the classic errors: multiplying entry by entry, multiplying mismatched sizes, or assuming AB=BA.

Intuitive Explanation

Two friends order at a café. Ali buys 2 coffees and 1 muffin; Bea buys 1 coffee and 3 muffins. Coffee costs $4 and a muffin $3. Put the orders in a matrix and the prices in a column: [2113][43]=[2⋅4+1⋅31⋅4+3⋅3]=[1113]. Ali pays $11 and Bea $13. Each entry of the product runs along one row of the first matrix and down one column of the second, multiplying pairs and adding.

That pairing is why the sizes must fit. A row of A has as many entries as A has columns, and a column of B has as many entries as B has rows; they pair up only when those numbers match. An m×n matrix times an n×p matrix gives an m×p matrix: the inner numbers must agree, and the outer numbers give the size of the result. A 2×3 times a 3×4 is 2×4; a 2×3 times a 2×3 is undefined.

Order matters. With A=[1101] and B=[1011], AB=[2111] but BA=[1112]. Doing two transformations in the other order, such as turning then stretching instead of stretching then turning, usually changes the outcome.

Matrix addition looks similar but works position by position and needs identical sizes. A product needs only matching inner sizes, and every entry mixes a whole row with a whole column.

Think of it like this. Matrix multiplication works like a shop checkout: each row of A is one customer's basket, each column of B is a price list, and each entry of AB is one basket rung up on one price list. The basket and the price list must cover the same items, which is the inner-size rule. The picture does not explain why BA differs from AB; swapping the order changes which matrix plays the baskets.

Core idea. Each result entry is the dot product of a row of A with a column of B, and inner dimensions must match.


When to Use

Use it when one table's columns line up with another table's rows: quantities times prices, or a coefficient matrix times a column of unknowns as in Ax=b. It also composes transformations: doing B and then A is the single matrix AB. Check the inner dimensions first. If the matrices have the same size and you want totals or differences position by position, add or subtract instead; if one factor is a single number, it is a scalar multiple.

Tip. Ask: Does the column count of A equal the row count of B, and am I dotting rows with columns?

How to Recognize It

Before multiplying two matrices, check what the rows of the first and the columns of the second stand for, and whether they describe the same items.

  1. Does each column of the first table stand for the same items as each row of the second, such as products in both?

    Yes means the tables chain: quantities of each product times the price of each product. If instead the two tables have the same layout and you want totals, add them entry by entry.

  2. Is one of the two factors just a single number?

    A single number scales every entry, which is scalar multiplication and needs no size check. Row-by-column multiplication is only for two genuine matrices.

  3. Are the factors one row and one column of the same length?

    Then the product is one number, the dot product of two vectors. It is the smallest case of matrix multiplication, the building block repeated for every entry of a bigger product.

  4. Does the order of the two steps or tables matter in the story?

    Usually it does: a rotation followed by a stretch differs from a stretch followed by a rotation, and AB is generally not BA. Keep the order from the story; a problem that reverses it is asking for a different product.

Matrix Multiplication compared with Matrix addition, Scalar multiplication, and Dot product (vectors)

These rows all combine arrays of numbers, and three of them are some kind of multiplying. Sort them by what meets what: a number times every entry, one row times one column, rows of one matrix times columns of another, or matching positions added.

Matrix Multiplication

Meaning
Use this when you compose two matrices and the columns of the first match the rows of the second.
Key test
Does the column count of A equal the row count of B, and am I dotting rows with columns?
Formula
(AB)ij=∑k=1naik⋅bkj
Example
Compute AB for A=[1234], B=[5678].

Matrix addition

Meaning
Combines entrywise; needs identical dimensions.
Key test
Use when joining same-size matrices with +, not composing them.
Formula
(A+B)ij=aij+bij
Example
2×2 plus 2×2

Scalar multiplication

Meaning
Multiplies a matrix by a single number.
Key test
Use when the multiplier is a plain number, not a matrix.
Formula
(kA)ij=k aij
Example
3A

Dot product (vectors)

Meaning
The single-number building block of each entry.
Key test
Use when multiplying one row vector by one column vector.
Formula
u⋅v=∑uivi
Example
⟨1,2⟩⋅⟨3,4⟩=11

Formula & Notation

(AB)ij=∑k=1naik⋅bkj
For A∈Rm×n, B∈Rn×p: (AB)ij=∑k=1naikbkj, yielding AB∈Rm×p. Matrix multiplication is associative (A(BC)=(AB)C) but not commutative (AB≠BA in general).

How to read it: AB means multiply A by B (row-by-column). Dimensions: (m×n)(n×p)=(m×p). The inner dimensions must match.

Worked Examples

Example 1 — Multiply two matrices

Easy

Compute AB for A=[1234], B=[5678].
Show the steps and the answer
  1. Check sizes: (2×2)(2×2) has inner numbers 2 and 2, so AB exists and is 2×2.

    The inner numbers must match, and the outer numbers give the size of the result.

  2. Row 1 of A with column 1 of B: 1⋅5+2⋅7=5+14=19.

    Entry (1,1) pairs the first row with the first column.

  3. Row 1 with column 2: 1⋅6+2⋅8=6+16=22.

    Staying on row 1 fills the first row of the answer.

  4. Row 2 with each column: 3⋅5+4⋅7=15+28=43 and 3⋅6+4⋅8=18+32=50.

    Row 2 of A produces row 2 of AB.

Answer: [19224350]

Takeaway: Entry (i,j) of AB is row i of A times column j of B, multiplied pair by pair and added.

Example 2 — Addition, not multiplication

Standard

Compute A+B for the same matrices.
Show the steps and the answer
  1. Read the sign: A+B asks for a sum, not a product.

    Addition pairs each entry with the one in the same position; no row meets a column.

  2. Check sizes: both are 2×2, so the sum exists.

    Addition needs identical sizes, a stricter rule than the product's matching inner numbers.

  3. Add matching entries: [1+52+63+74+8]=[681012].

    Each entry of A+B uses just two numbers, while each entry of AB adds two products.

Answer: [681012]

Takeaway: A plus sign means position-by-position addition; the row-by-column rule is only for products.

Example 3 — Find the mistake: which sizes must match

Application

Let C=[1203−14] and D=[2105]. Omar writes: "CD is 2×2 because both matrices have 2 rows," and starts multiplying. Find the mistake, then decide whether DC exists and compute it.
Show the steps and the answer
  1. Write the sizes: C is 2×3 and D is 2×2.

    The rule compares the columns of the first factor with the rows of the second, not the rows of both.

  2. Test CD: (2×3)(2×2) has inner numbers 3 and 2, so CD is undefined.

    A row of C has 3 entries but a column of D has only 2, so they cannot be paired.

  3. Test DC: (2×2)(2×3) has inner numbers 2 and 2, so DC exists and is 2×3.

    Reversing the order can make a product possible.

  4. Row 1 of D, which is (2,1), with each column of C: 2+3=5, 4−1=3, 0+4=4.

    Each column of C is paired with the same row of D in turn.

  5. Row 2 of D, which is (0,5): 0+15=15, 0−5=−5, 0+20=20.

    The second row of D gives the second row of DC.

Answer: CD is undefined; DC=[53415−520].

Takeaway: Compare the first factor's columns with the second factor's rows before multiplying; when they differ, the product does not exist.

Where You'll See It

  • Ringing up several orders at once

    Three customers' orders of burgers, fries and drinks form a 3×3 matrix, and the prices $6, $3 and $2 form a 3×1 column. The product is a column of three bills: an order of 2 burgers, 1 fries and 2 drinks costs 2(6)+1(3)+2(2)=19 dollars.

  • Rotating a game character

    A 90∘ counterclockwise turn is the matrix R=[0−110], and R[31]=[−13]. Game engines multiply every corner of a model by matrices like this, and RR=[−100−1] is a half turn.

  • Nutrition totals for a meal

    A row of servings, 2 rice, 1 beans, 1 chicken, times a 3×2 matrix of calories and protein per serving, rice (200, 4 g), beans (110, 7 g), chicken (165, 31 g), gives 2(200)+110+165=675 calories and 2(4)+7+31=46 g of protein.

Common Mistakes

  1. The slip: Multiplying when inner dimensions disagree

    Instead: (2×3)(2×2) is undefined; the inner numbers must match.

  2. The slip: Assuming AB=BA

    Instead: matrix multiplication is generally non-commutative, so order matters.

  3. The slip: Multiplying entrywise

    Instead: each result entry is a row-by-column SUM of products, not a single product.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. Compute [2103][1421].

    Hint: Each entry is a row of the first matrix times a column of the second.

  2. Compute [123][456] and give the size of the result.

    Hint: Multiply matching entries and add.

  3. A is 2×3 and B is 3×4. Is AB defined? Is BA? Give the size of any product that exists.

    Hint: The inner numbers must match.

  4. For A=[1101] and B=[1011], compute AB and BA.

    Hint: Do both products row by column and compare.

  5. Matrix Q (3×2) holds quantities of 2 items sold at 3 stores, and p (2×1) holds the item prices. To get each store's revenue, multiply or add?

    Hint: Revenue is quantity times price, summed over items.

  6. A student multiplies [1234][2013] entry by entry and gets [20312]. Correct it.

    Hint: Each entry is a sum of products, row by column.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why is multiplication defined in such a strange way instead of entry by entry?

Because the row-by-column rule is what makes the product mean something useful. If BB moves a point to a new place and AA then moves it again, the single matrix that does both jobs is exactly ABAB, computed row by column. The same rule turns quantities and prices into totals. An entry-by-entry product does exist, called the Hadamard product, but it has none of these meanings and plays a small role in algebra.

If AB exists, does BA exist too?

Not necessarily. A 2×32\times3 matrix times a 3×43\times4 matrix gives a 2×42\times4 answer, but the reverse order puts a 3×43\times4 in front of a 2×32\times3, and the inner sizes 4 and 2 do not match, so BABA is undefined. Both orders exist when the sizes are m×nm\times n and n×mn\times m, and even then the answers can differ in size: a 2×32\times3 times a 3×23\times2 is 2×22\times2, but the other order is 3×33\times3.

Is there a matrix that acts like the number 1?

Yes, the identity matrix II, with 1s down the main diagonal and 0s everywhere else. For any square matrix AA of the same size, AI=IA=AAI=IA=A, because each row-by-column product picks out exactly one entry of AA. For 2×22\times2 matrices, I=[1001]I=\begin{bmatrix}1&0\\0&1\end{bmatrix}. It is the target when you look for an inverse: the matrix A−1A^{-1} with AA−1=IAA^{-1}=I.

Can two nonzero matrices multiply to give the zero matrix?

Yes, which never happens with ordinary numbers. Take A=[1000]A=\begin{bmatrix}1&0\\0&0\end{bmatrix} and B=[0001]B=\begin{bmatrix}0&0\\0&1\end{bmatrix}: every row of AA dotted with every column of BB gives 0, so ABAB is the zero matrix. This is why you cannot argue "AB=OAB=O, so A=OA=O or B=OB=O" as you would with numbers, and why matrix equations need extra care.

Learning Path

You need Matrix Definition (sizes and entries) and Matrix Addition, Subtraction, and Scalar Multiplication first. This concept adds the row-by-column product and the size rule (m×n)(n×p)=m×p. Next, the Determinant measures how a square matrix scales area, the Inverse Matrix undoes a product, and Solving Systems of Equations with Matrices writes a whole system as Ax=b.

See Also