How to Multiply Matrices (and Why AB Is Not BA)

Math September 2, 2026

Matrix multiplication is row by column, not cell by cell, and reversing the order changes the answer.

Quick answer: Matrix multiplication is not element by element. Each entry of the product is one row of the first matrix combined with one column of the second, multiplying pairs and adding the results. An m×n matrix times an n×p matrix gives an m×p answer, the inner dimensions have to match, and order matters: AB rarely equals BA.

Most matrix errors come from one wrong assumption, which is that multiplying two matrices works like multiplying two spreadsheets cell by cell. It does not. That mistake at least produces an answer of the wrong size, which is obvious. The subtler trap is reversing the order and getting a plausible result that is not the product you wanted.

The rule that trips everyone up

Write the two shapes side by side. A 2×3 matrix times a 3×4 matrix works, because the 3 in the middle matches, and the answer is 2×4. A 2×3 times a 2×3 does not work at all. The outer numbers give the shape of the result, the inner numbers have to agree, and if they do not, there is no product to find.

Working a 2×2 product by hand

Take A = [[2, 1], [0, 3]] and B = [[4, 5], [6, 7]]. The top-left entry of AB uses the first row of A and the first column of B: (2 × 4) + (1 × 6) = 14. Top-right pairs that same row with the second column: (2 × 5) + (1 × 7) = 17. The second row of A gives (0 × 4) + (3 × 6) = 18 and (0 × 5) + (3 × 7) = 21. So AB = [[14, 17], [18, 21]].

Why AB is not BA

Now reverse them. BA = [[8, 19], [12, 27]]. Same two matrices, same arithmetic, completely different answer. That is normal rather than a special case, and it is why "multiply the matrices" is an incomplete instruction. In graphics work it is the reason rotating then scaling puts an object somewhere different from scaling then rotating.

Run your own numbers

It is free, there is no sign-up, and it works on your phone.

Open the Matrix Calculator

Determinants and inverses, and when they fail

For a 2×2 matrix [[a, b], [c, d]], the determinant is ad minus bc. Take [[3, 8], [4, 6]]: that is (3 × 6) - (8 × 4) = 18 - 32 = -14. The inverse is the determinant divided into a rearranged version of the original, giving [[-0.4286, 0.5714], [0.2857, -0.2143]] to four decimal places.

Notice what happens if the determinant comes out as zero. Dividing by it is impossible, so the matrix has no inverse. It is called singular, and it means the rows carry duplicate information: one is a multiple of another. A calculator will tell you this rather than returning nonsense, which is one good reason to check a hand-computed inverse against one. If you are working through a wider set of tools, the roundup of free online math calculators covers what else pairs well with matrix work.

Try it with your figures

No sign-up, no ads. Your inputs stay in your browser.

Use the Matrix Calculator

Using the matrix calculator

Set the dimensions first. The calculator asks for rows and columns for matrix A and matrix B before it shows you any input boxes, and picking the sizes up front stops you pasting a 3×3 worth of numbers into a 2×2 grid. Enter values row by row, left to right, exactly as they are written in your textbook or problem sheet.

Then choose the operation. Addition and subtraction need both matrices to be the same size. Multiplication only needs the inner dimensions to match. Determinant, inverse and transpose act on a single matrix, so only the A grid matters for those. Fractions and negatives can go in directly, and keeping fractions usually gives a cleaner answer.

Read the output as a check on your own working rather than a replacement for it. When the two disagree, the mismatch is almost always one entry, and comparing row by row finds it fast. For plotting the transformations these matrices describe, a graphing calculator makes the geometry visible.

Check your own case

Free to use, and it takes less than a minute.

Open the Matrix Calculator

Common questions

Can you multiply a 3×2 matrix by a 3×2 matrix? No. The inner dimensions are 2 and 3, which do not match. Transposing the second one to 2×3 would make it work, and the product would be 3×3.

What does a determinant of zero mean? The matrix cannot be inverted, and the system of equations it represents either has no solution or infinitely many. Geometrically it means the transformation squashes space flat, collapsing area or volume to nothing.

How do I solve a system of equations with a matrix? Write it as AX = B, where A holds the coefficients and B the constants. If A has an inverse, X equals the inverse of A multiplied by B. Three equations in three unknowns become a 3×3 inverse and one multiplication.

Is the transpose the same as the inverse? No. The transpose flips rows into columns and always exists. The inverse undoes the original transformation, and plenty of matrices do not have one.

Calculators for this

All free, no sign-up.

Have a question, a correction, or a calculator request? Contact our editorial team — we usually reply within a day.