Matrix Multiplication
Matrix multiplication combines two matrices so that each entry of the product is the dot product of a row of A with a column of B. The number of columns of A must equal the number of rows of B.
Why the definition is shaped that way
Matrix multiplication is not what its name suggests. Nothing is multiplied position by position; instead each entry of the product is built from an entire row of the first matrix and an entire column of the second. The definition looks arbitrary until you see what it is for — and then it becomes the only sensible one.
This calculator multiplies two matrices, checking first that their dimensions allow it, and returns the product with its own dimensions reported.
A matrix describes a transformation: feed in a vector, get a vector out. Multiplying two matrices is meant to produce the single matrix that does what applying both in turn would do — and working out what that composite transformation is forces exactly the row-against-column rule.
That origin explains everything else about the operation. It explains why the inner dimensions must agree, why the order of the factors matters, and why the product's shape comes from the outer dimensions rather than from either matrix alone.
How to use this calculator
- Enter matrix A Commas between entries, semicolons between rows. Its column count is what constrains what can follow it.
- Enter matrix B Its row count must equal A's column count. A mismatch is reported with both sets of dimensions so the offending pair is obvious.
- Check the two dimension lines Both matrices are echoed with their sizes. The two inner numbers must match; the two outer ones become the shape of the answer.
- Read the product Its entry in row i, column j came from row i of A and column j of B — nothing else contributed to it.
The formula, and where it comes from
(A·B)ᵢⱼ = Σₖ Aᵢₖ · Bₖⱼ (m×n)·(n×p) = m×p
Each entry of the product is a dot product: walk along row i of the first matrix and down column j of the second, multiply the paired entries, and add. The index being summed over is the one the two matrices share, which is precisely why they must agree on it.
That shared index is consumed by the summation and disappears from the result. What survives is the row count of the first matrix and the column count of the second — so a wide matrix times a tall one gives something small, and a tall one times a wide one gives something large.
The rule is exactly what composing two transformations requires. Applying B and then A to a vector gives the same result as applying the single matrix A·B, and expanding that requirement coordinate by coordinate produces the sum above rather than any simpler alternative.
Because each entry is a sum of products, whole-number inputs give whole-number outputs exactly, but the arithmetic per entry grows with the shared dimension. A single entry of a product of two large matrices is already a long sum.
What each input means
- A First matrix — form field “Matrix A”
- The left factor, applied second when the product is read as a composition. Its rows are paired against B's columns.
- B Second matrix — form field “Matrix B”
- The right factor, applied first as a transformation. Its row count must equal A's column count.
- A·B Product
- Has as many rows as A and as many columns as B. It generally differs from B·A, which may not even be defined.
Worked examples
Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.
Two square matrices
Multiply the matrix with rows (1, 2) and (3, 4) by the one with rows (5, 6) and (7, 8). Both are 2×2, so the product is too.
Inputs Matrix A = 1, 2; 3, 4, Matrix B = 5, 6; 7, 8
- Matrix A 2×2 [[1, 2], [3, 4]]
- Matrix B 2×2 [[5, 6], [7, 8]]
- Rule Each entry (i,j) is the dot product of row i of A with column j of B.
- Product A·B [[19, 22], [43, 50]]
Result [[19, 22], [43, 50]]
The top-left entry pairs the first row of A against the first column of B — so it uses 1 and 2 from one matrix and 5 and 7 from the other, not 5 and 6. Reading down a column rather than across a row is the step that has to be done deliberately.
Reversing the two matrices here gives a different product, even though both orders are defined because the matrices are square. Non-commutativity is not an edge case; it is the normal situation.
Rectangular matrices whose dimensions chain
Multiply a 2×3 matrix by a 3×2 one. The inner dimensions agree at 3, so the product exists and comes out 2×2.
Inputs Matrix A = 1, 2, 3; 4, 5, 6, Matrix B = 7, 8; 9, 10; 11, 12
- Matrix A 2×3 [[1, 2, 3], [4, 5, 6]]
- Matrix B 3×2 [[7, 8], [9, 10], [11, 12]]
- Rule Each entry (i,j) is the dot product of row i of A with column j of B.
- Product A·B [[58, 64], [139, 154]]
Result [[58, 64], [139, 154]]
Each entry now sums three products rather than two, because the shared dimension is 3. That count is set by the inner dimension and has nothing to do with the size of the answer.
Reversing these two is also defined, but produces a 3×3 matrix rather than a 2×2 one. The two products are not merely different values — they are different shapes, which makes the asymmetry hard to miss.
Reading the result
Reading the dimensions as a chain
Write the two shapes side by side: the adjacent numbers must match and then vanish, leaving the outer pair as the product's shape. That single glance settles both whether a product is defined and how large it will be.
Order is part of the meaning
A·B and B·A are different questions, not different notations for one. As transformations they describe applying the same two operations in opposite orders, which generally lands somewhere else — rotating then reflecting is not reflecting then rotating.
A zero product does not mean a zero factor
Two non-zero matrices can multiply to the zero matrix, which is impossible for ordinary numbers. It happens when the first matrix annihilates exactly the directions the second produces.
When you would use this
Composing transformations
Combining a rotation with a scaling, or chaining several coordinate changes, is done by multiplying their matrices once. The composite can then be applied repeatedly at the cost of a single transformation.
Applying a matrix to a vector
A column vector is a matrix with one column, so applying a transformation is a special case of multiplication. The dimension rule then says the matrix's column count must match the vector's length.
Assumptions and limitations
What this calculator assumes
- The column count of the first matrix equals the row count of the second.
- Entries are real numbers, with commas between columns and semicolons between rows.
- The product is A·B in the order the fields are given; the reverse is a separate calculation.
- The product has the row count of the first matrix and the column count of the second.
Where it stops being the right tool
- Two matrices at a time: a longer chain must be built in stages, though the order can be grouped freely since multiplication is associative.
- No scalar multiplication, powers or exponentials of a matrix.
- The individual dot products are not itemised — only the rule and the finished product are shown.
- Numeric entries only, with no symbolic or complex values.
Common mistakes
Multiplying entry by entry
Why it happens. Addition of matrices works that way, and the same two input boxes appear here, so the habit transfers. Entrywise multiplication is a genuine operation in some contexts, but it is not this one.
How to avoid it. Pair a whole row against a whole column. If your top-left entry used only the two top-left entries of the inputs, the wrong rule was applied.
Reading down the first matrix and across the second
Why it happens. The rule is symmetric-looking and easy to invert from memory, and the mistake produces a matrix of the right shape with plausible numbers.
How to avoid it. Rows from the left factor, columns from the right. Checking a single off-diagonal entry against the tool distinguishes this from an arithmetic slip.
Assuming a defined product means both orders work
Why it happens. For square matrices both orders are always defined, which builds the expectation that they are interchangeable.
How to avoid it. Compute both if it matters. For rectangular matrices the shapes usually differ; for square ones the values usually do.
Learn why this works
Key terms
Frequently asked questions
When can two matrices be multiplied?
When the number of columns of the first equals the number of rows of the second. That shared dimension is the one summed over, so without agreement there is nothing to pair up.
Is matrix multiplication commutative?
No. A·B generally differs from B·A, and for rectangular matrices one order may not even be defined. As transformations the two products describe applying the same operations in opposite orders, which lands in different places.
What are the dimensions of the product?
If the first matrix is m×n and the second n×p, the product is m×p. The shared inner dimension is consumed by the summation, leaving the outer two.
Why is the rule so complicated?
Because it is not chosen for convenience but forced by what the operation must do. Requiring that the product represent the composition of two transformations determines the row-against-column rule uniquely.