What matrix multiplication actually does
Matrix multiplication looks arbitrary until you know what it is for: it is composition of linear maps. If B transforms space and then A transforms the result, the single matrix that does both in one step is AB. The strange-looking row-times-column rule is forced by that requirement — it is the only definition that makes composing maps agree with multiplying their matrices.
That explains every rule you have to remember. The inner dimensions must match because B's output lives in the space A takes as input. The order matters because doing B then A is not the same as doing A then B — rotate a book 90° about one axis and then another, then repeat in the opposite order, and the book ends up somewhere different. And the product is m×p because the composite map takes p-dimensional input to m-dimensional output.
Concretely, entry (i, j) of AB is the dot product of row i of A with column j of B. Each entry answers one narrow question: how much does the j-th input direction contribute to the i-th output coordinate?
The dimension rule, and how to check it in one glance
Write the shapes side by side: (m×n)(n×p). The two inner numbers must be equal, and they cancel; the two outer numbers survive as the shape of the answer. A 2×3 times a 3×2 gives a 2×2. A 3×2 times a 2×3 gives a 3×3. Same two matrices, different order, different shape — which is the fastest way to see that AB and BA are not the same object even when both exist.
Two special cases are worth naming because they are most of the multiplication anyone does in practice. A matrix times a column vector is an (m×n)(n×1) product, giving an m×1 column: this is the operation Ax that a linear system is built from. A row vector times a matrix is (1×m)(m×n), giving a 1×n row.
Powers only make sense for square matrices, since A² needs A's columns to match A's own rows. A⁰ is defined as the identity, exactly as x⁰ = 1. Powers of a matrix have real meaning: if A is the transition matrix of a Markov chain, Aⁿ gives the n-step transition probabilities; if A is the adjacency matrix of a graph, entry (i, j) of Aⁿ counts the walks of length n from node i to node j.
The cost of a straightforward product is m·n·p multiplications and about the same number of additions. For two n×n matrices that is n³, which is why multiplying two 1,000×1,000 matrices is a billion operations and why faster algorithms such as Strassen's exist at all.
Worked example: [[1, 2], [3, 4]] × [[5, 6], [7, 8]]
Both matrices are 2×2, so the inner dimensions match and the answer is 2×2. Four entries, four dot products.
- Entry (1,1). Row 1 of A is (1, 2); column 1 of B is (5, 7). Dot them: 1×5 + 2×7 = 5 + 14 = 19.
- Entry (1,2). Row 1 of A against column 2 of B, which is (6, 8): 1×6 + 2×8 = 6 + 16 = 22.
- Entry (2,1). Row 2 of A is (3, 4), against column 1 of B: 3×5 + 4×7 = 15 + 28 = 43.
- Entry (2,2). Row 2 of A against column 2 of B: 3×6 + 4×8 = 18 + 32 = 50.
So AB = [[19, 22], [43, 50]]. The trace is 19 + 50 = 69, the entries sum to 134, and the Frobenius norm is √(19² + 22² + 43² + 50²) = √(361 + 484 + 1849 + 2500) = √5194 = 72.069411.
Now reverse the order. BA has entry (1,1) equal to row 1 of B against column 1 of A: 5×1 + 6×3 = 23, not 19. Working the rest out gives BA = [[23, 34], [31, 46]], with trace 23 + 46 = 69. The traces agree — that is the identity tr(AB) = tr(BA), which holds for every pair whose product is defined both ways — but the matrices themselves are completely different. This is what non-commutativity looks like in four numbers.
Reading the summary figures
The headline figure is the (1,1) entry — row 1 of the left matrix dotted with column 1 of the right. It is the first thing you compute by hand and the first thing to check against someone else's answer, and unlike the trace it exists for every product, including a matrix times a column vector. The full result matrix sits in the table below it.
The trace is the sum of the diagonal, and it exists only when the result is square. It is invariant under a change of basis and equals the sum of the eigenvalues, which makes it a quick fingerprint of a transformation. The identity tr(AB) = tr(BA) holds even when AB and BA have different sizes, which is used constantly in proofs.
The Frobenius norm is the square root of the sum of the squares of every entry — the ordinary Euclidean length of the matrix read as a long vector. It is the standard way to answer “how big is this matrix?” and the standard way to measure the gap between two matrices as ‖A − B‖F.
The largest entry and the sum of entries are practical sanity checks. If you multiply two matrices of entries around 10 with an inner dimension of 3, expect entries around 300; a result of 3 or 30,000 means something is wrong with the shapes or the transcription.
Watch for a result that is all zeros without either input being zero. That is genuinely possible — [[1,0],[0,0]] times [[0,0],[0,1]] is the zero matrix — and it is one of the properties that makes matrices unlike numbers. A zero product does not imply a zero factor.
Which shapes multiply, and what comes out
| A | B | AB defined? | Shape of AB | BA defined? |
|---|---|---|---|---|
| 2×2 | 2×2 | Yes | 2×2 | Yes, usually different |
| 2×3 | 3×2 | Yes | 2×2 | Yes, but 3×3 |
| 3×2 | 2×3 | Yes | 3×3 | Yes, but 2×2 |
| 2×2 | 2×1 | Yes | 2×1 | No |
| 1×3 | 3×1 | Yes | 1×1 (a scalar) | Yes, but 3×3 |
| 2×2 | 3×2 | No — 2 ≠ 3 | — | Yes, 3×2 |
| 3×3 | 3×3 | Yes | 3×3 | Yes, usually different |
The 1×3 times 3×1 row is the dot product; the 3×1 times 1×3 in the other order is the outer product, a rank-one 3×3 matrix.
The rules that are not what you expect
- AB ≠ BA in general. This is the big one. Both products may exist, have different shapes, or one may not exist at all. Some special pairs do commute — any matrix with the identity, any two diagonal matrices, any matrix with its own powers — but the general rule is that order matters.
- AB = 0 does not mean A = 0 or B = 0. Two non-zero matrices can multiply to nothing, because one can map everything into the null space of the other.
- AB = AC does not mean B = C. Cancellation is only valid when A is invertible, since you are really multiplying by A⁻¹.
- (AB)ᵀ = BᵀAᵀ and (AB)⁻¹ = B⁻¹A⁻¹. Transposing and inverting both reverse the order.
- The product is associative: (AB)C = A(BC). The grouping is free but the order is not, and the grouping you choose can change the operation count enormously for chains of differently-shaped matrices.
- Multiplying element by element is a different operation. The entrywise product used in spreadsheets and array languages is the Hadamard product, not this. It requires identical shapes and has no connection to composing maps.
Powers of a matrix count paths
Let A be the adjacency matrix of a graph, with a 1 wherever two nodes are joined. Then entry (i, j) of An is exactly the number of walks of length n from node i to node j, because the sum over intermediate nodes in the multiplication rule is the enumeration of those walks. Applying the same idea to the matrix [[1,1],[1,0]] gives the Fibonacci numbers: its n-th power is [[Fn+1, Fn], [Fn, Fn−1]], which you can verify above by setting the exponent to 3 and reading off [[3,2],[2,1]].
Where to go next
Multiplication is the check on almost every other matrix computation. Multiply a matrix by its claimed inverse and you should get the identity — that is exactly the residual the matrix inverse calculator reports. Multiply A by a claimed eigenvector and you should get a scalar multiple of that vector, which is the definition the eigenvalue calculator works from.
The determinant is multiplicative across products: det(AB) = det(A)·det(B), so composing two maps multiplies their volume factors. Check it with the determinant calculator on A, on B and on AB. For solving Ax = b rather than forming products, go to the RREF calculator, and for factoring a matrix into a product of triangular pieces, the LU decomposition calculator.
Each individual entry of the product is a dot product, so if you want to see one of them in isolation with the geometry attached — magnitudes, angle, orthogonality — the dot product calculator takes the row and the column directly.
