Audited 29 Jul 2026·Last updated 28 Oct 2026·6 citations·Tier 1·0 uses

Matrix Multiplication Calculator

Multiply two matrices up to 10 × 10 in either order, AB or BA, and see the product's shape, the inner dimension and the number of multiplications used.

Matrix Multiplication Calculator

Which product?
One row per line. Separate entries with spaces or commas. Max 10 × 10.
For A × B the number of rows here must equal the number of columns in A.
Product matrix
[58 64; 139 154]
The row-by-column product of the two matrices in the order you chose, written with semicolons between rows.
Rows
2
Columns
2
Inner dimension
3
Scalar multiplications
12
Sum of entries
415

Background.

Ask someone new to linear algebra to multiply [1 2; 3 4] by [5 6; 7 8] and the usual first answer is [5 12; 21 32]: one times five, two times six, and so on, position by position. That operation exists — it is called the Hadamard product — but it is not what matrix multiplication means in algebra, physics, statistics or computing. The standard product is [19 22; 43 50]. Each entry pairs a whole row of the left matrix with a whole column of the right one: the top-left is 1·5 + 2·7 = 19, the bottom-right 3·6 + 4·8 = 50.

That row-by-column rule has consequences people trip over. The two matrices do not have to be the same size; they only have to agree on one number, the columns of the left factor against the rows of the right. A 2 × 3 matrix times a 3 × 2 matrix is fine and gives a 2 × 2 answer. Order matters as well. Swap the two 2 × 2 matrices above and the product becomes [23 34; 31 46], and for non-square matrices one order can exist while the other does not.

The rule is not arbitrary, and it was already set out in Arthur Cayley's 1858 memoir on matrices. A matrix describes a linear transformation — a rotation, a reflection, a stretch, a change of coordinates — and multiplying two matrices gives the single matrix that performs one transformation after the other. Rotate the plane an anticlockwise quarter-turn and then reflect it in the x-axis, and you get [0 −1; −1 0], a reflection in the line y = −x. Reflect first and then rotate, and you get [0 1; 1 0], a reflection in y = x. Different orders, different results, exactly as with the matrices.

Enter each matrix with one row per line and entries separated by spaces or commas, choose A × B or B × A, and the result shows the product with semicolons between its rows, along with its dimensions, the inner dimension that was summed over, how many number-by-number multiplications it took, and the sum of all entries as a check figure. Each matrix can have up to ten rows and ten columns. For entry-wise products, addition and scalar multiplication, use the general matrix calculator.

What is matrix multiplication calculator?

Matrix multiplication, sometimes called the Cayley product to distinguish it from entry-wise and Kronecker products, combines an m × n matrix A with an n × p matrix B into an m × p matrix AB. The entry in row i and column j is the sum, over k from 1 to n, of aᵢₖ times bₖⱼ. The product exists only when the left factor's column count equals the right factor's row count; that shared count, the inner dimension, disappears from the result. The operation is associative, (AB)C = A(BC), and distributes over addition, A(B + C) = AB + AC. The identity matrix, with ones on the main diagonal and zeros elsewhere, leaves any compatible matrix unchanged. Two properties of ordinary numbers do not carry over: AB and BA are generally different, and two non-zero matrices can multiply to the zero matrix.

How to use this calculator.

  1. Type Matrix A one row per line, separating entries with spaces or commas; "1 2 3" above "4 5 6" is a 2 × 3 matrix. You can also put a whole matrix on one line with semicolons between rows, as in 1,2,3;4,5,6.
  2. Type Matrix B the same way. Every row must have the same number of entries, and no matrix may exceed ten rows or ten columns.
  3. Choose the order. A × B puts A on the left and needs A's column count to equal B's row count; B × A needs the reverse. If the sizes do not fit, the message names both shapes and the counts that must match.
  4. Read the product: [58 64; 139 154] means a first row of 58 and 64 and a second row of 139 and 154. Its rows always come from the left factor and its columns from the right.
  5. If you are checking a hand calculation, compare your sum of entries with the one shown before hunting for the wrong entry.

The formula.

(AB)ᵢⱼ = Σₖ aᵢₖ · bₖⱼ

The definition is (AB)ᵢⱼ = Σₖ aᵢₖ · bₖⱼ, with k running from 1 to n: walk along row i of A and down column j of B together, multiply the pairs and add. Row i of A has n entries and column j of B has n entries, which is the whole reason the inner dimensions must match.

The same arithmetic can be read in several ways, and Gilbert Strang's MIT linear algebra course teaches them side by side. Entry by entry, each element of AB is a dot product of a row with a column. Column by column, each column of AB is A multiplied by the matching column of B, so it is a combination of A's columns. Row by row, each row of AB is the matching row of A multiplied by B, a combination of B's rows. And as a sum of pieces, AB is the total of n outer products, column k of A times row k of B. In the default example these three pieces are [7 8; 28 32], [18 20; 45 50] and [33 36; 66 72], which add to [58 64; 139 154].

The work counts follow directly. There are m × p entries and each takes n multiplications, so the product costs m × n × p multiplications: 12 for a 2 × 3 by 3 × 2, and n³ for two n × n matrices, 1,000 for a pair of 10 × 10s. That cubic growth is why matrix-matrix routines, the Level 3 BLAS, are among the most heavily optimised code in numerical computing.

Two identities are worth knowing because they let you check or reorganise a calculation. Transposing a product reverses the order, (AB)ᵀ = BᵀAᵀ; multiplying the transposes of the default matrices gives [58 139; 64 154], the transpose of the original answer. And a product with a matrix of all-zero rows or columns inherits them: a zero row in A gives a zero row in AB, a zero column in B gives a zero column in AB.

A worked example.

Example

Take the default matrices: A = [1 2 3; 4 5 6], which is 2 × 3, and B = [7 8; 9 10; 11 12], which is 3 × 2. A has three columns and B has three rows, so A × B exists with an inner dimension of 3, and the answer has A's 2 rows and B's 2 columns. Row 1 of A is (1, 2, 3). Against column 1 of B, (7, 9, 11), it gives 1·7 + 2·9 + 3·11 = 7 + 18 + 33 = 58; against column 2, (8, 10, 12), it gives 8 + 20 + 36 = 64. Row 2 of A is (4, 5, 6): against column 1 it gives 28 + 45 + 66 = 139, and against column 2 it gives 32 + 50 + 72 = 154. The product is [58 64; 139 154]. Four entries at three multiplications each makes 2 × 3 × 2 = 12 multiplications. The entries add up to 58 + 64 + 139 + 154 = 415, and that total can be predicted without doing the product at all. Add up each column of A to get (5, 7, 9) and each row of B to get (15, 19, 23); their dot product is 75 + 133 + 207 = 415. When the two totals agree, your arithmetic is very likely right.

matrix B7 8 9 10 11 12
matrix A1 2 3 4 5 6
orderAB

Frequently asked questions.

Why won't my 2 × 3 and 2 × 2 matrices multiply?
For A × B, A's three columns would have to pair with three rows of B, and B has only two, so the result reports that A is 2×3 and B is 2×2 and that the counts must match. The other order works: B × A is a 2 × 2 times a 2 × 3, which gives a 2 × 3 matrix. With A = [1 2 3; 4 5 6] and B = [1 2; 3 4], B × A is [9 12 15; 19 26 33].
Which matrices give the same answer in either order?
Only special pairs, called commuting matrices. Any matrix commutes with the identity, with multiples of the identity and with its own powers; two diagonal matrices of the same size always commute; and a matrix commutes with its inverse. Rotations of the plane about the same point commute with each other too. Outside cases like these, expect AB and BA to differ, as [1 2; 3 4] and [5 6; 7 8] do.
How are the Hadamard and Kronecker products different from this one?
The Hadamard product multiplies entries in matching positions, so both matrices must be the same size and the result is that size too: [1 2; 3 4] and [5 6; 7 8] give [5 12; 21 32]. The Kronecker product multiplies every entry of A by the whole of B and tiles the results, so an m × n and a p × q give an mp × nq block matrix. Neither is computed here; the Encyclopedia of Mathematics lists all three under one heading.
Can I use this to get a dot product or an outer product of two vectors?
Yes, by entering the vectors as a single row and a single column. Row "1 2 3" times a column of 4, 5 and 6 gives the 1 × 1 matrix [32], which is the dot product 1·4 + 2·5 + 3·6. Put the column on the left instead and the answer is the 3 × 3 outer product [4 8 12; 5 10 15; 6 12 18]. The same two vectors give a single number in one order and nine numbers in the other.
Can two non-zero matrices multiply to give zero?
They can. [1 0; 0 0] times [0 0; 0 1] is the zero matrix, and so is the product in the other order, although neither factor is zero. The first matrix keeps only the x-direction and the second only the y-direction, so applying both leaves nothing. This is why you cannot cancel in matrix equations: AB = AC does not imply B = C unless A has an inverse.
Does the order of brackets in a chain of products matter?
Not for the answer, because multiplication is associative, but often for the effort. Take u, a 10 × 1 column, v, a 1 × 10 row, and w, another 10 × 1 column. (uv)w first builds a 10 × 10 matrix with 100 multiplications, then needs 100 more: 200 in total. u(vw) first reduces vw to a single number with 10 multiplications, then needs 10 more: 20 in total, for the identical result.
Is m × n × p multiplications the least work possible?
No. It is the cost of the schoolbook method computed here. In 1969 Volker Strassen showed that two 2 × 2 matrices, or 2 × 2 grids of blocks, can be multiplied with 7 multiplications instead of 8; applied recursively, that brings the cost of n × n matrices down to about n^2.81. Faster methods carry overheads, so for small matrices like the ones that fit here the direct method is the practical choice.
How does the sum of entries help me check my work?
The total of every entry in AB equals the column sums of A dotted with the row sums of B, which you can work out from the inputs alone. For the default matrices that is (5, 7, 9) · (15, 19, 23) = 415, matching the product. It catches arithmetic slips but not misplaced entries: writing the transpose [58 139; 64 154] by mistake gives the same 415.
Can I enter fractions, decimals or negative numbers?
Negative numbers, decimals and scientific notation such as 1e3 are all accepted, and decimal entries are multiplied without binary rounding error, so 0.1 × 0.3 + 0.2 × 0.4 comes out as 0.11. Fractions written with a slash, such as 1/2, are not read. Enter a decimal instead, and keep enough digits: 0.3333333333 times 3 gives 0.9999999999, not 1. Results show at most ten decimal places.
Where does matrix multiplication turn up outside a maths course?
Almost anywhere linear relationships are chained. In a Markov chain, a transition matrix P = [0.9 0.1; 0.5 0.5] gives two-step probabilities P × P = [0.86 0.14; 0.7 0.3], so a system starting in state 1 is still there after two steps with probability 0.86. Graphics software composes rotations and scalings the same way, and each layer of a neural network multiplies its inputs by a weight matrix.

References& sources.

  1. [1]Encyclopedia of Mathematics (EMS Press / Springer), article "Matrix" — gives the product definition used here: for A ∈ M(m,k) and B ∈ M(k,n), AB = (c_{μν}) with c_{μν} = Σ_j a_{μj} b_{jν}. Retrieved 2026-07-29; open access.
  2. [2]Encyclopedia of Mathematics (EMS Press / Springer), article "Matrix multiplication" — names the row-by-column product "Cayley multiplication" and distinguishes it from Hadamard (entry-wise) and Kronecker multiplication, and relates it to composition of linear transformations. Retrieved 2026-07-29; open access.
  3. [3]NIST Digital Library of Mathematical Functions, §1.3(iv) "Matrices as Linear Operators" — matrices acting as linear operators, the framing that explains why the product is composition. Retrieved 2026-07-29; open access.
  4. [4]MIT OpenCourseWare 18.06 Linear Algebra, Spring 2010, Prof. Gilbert Strang — lectures on matrix multiplication, the four ways to view it, and its relationship to linear maps. CC BY-NC-SA 4.0; retrieved 2026-07-29; open access.
  5. [5]Netlib BLAS (Basic Linear Algebra Subprograms) reference site — "the Level 3 BLAS perform matrix-matrix operations"; the GEMM routines are the standard reference implementation of the product computed on this page. Retrieved 2026-07-29; open access.
  6. [6]Cayley, A. (1858). "A Memoir on the Theory of Matrices." Philosophical Transactions of the Royal Society of London 148, 17–37 — the paper that introduced the row-by-column product. DOI resolves; the publisher returned HTTP 403 to an unauthenticated request, so this is a bibliographic, gated citation rather than a page read in full.

How this page was produced

Published by
Quanta Calculator
Primary sources
6 cited below
Method
(AB)ᵢⱼ = Σₖ aᵢₖ · bₖⱼ
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon