MathIsimple
Math

Matrix Multiplication Calculator

Multiply two matrices with step-by-step solutions. Learn matrix multiplication rules.

100% FreeStep-by-Step Solutions
Matrix Multiplication Calculator
Enter two matrices. Matrix A columns must equal Matrix B rows.

Auto-set to match A columns

Try These Examples
Click on any example to automatically fill the calculator
Example 1

2×2 matrices

Matrix Multiplication Rules

For matrices A (m×n) and B (n×p), the product AB is defined only when:

  • Number of columns in A = Number of rows in B
  • Result matrix will be m×p
(AB)ij=k=1nAikBkj(AB)_{ij} = \sum_{k=1}^{n} A_{ik} B_{kj}
Important Properties

Not commutative: AB ≠ BA (in general)

Associative: (AB)C = A(BC)

Distributive: A(B+C) = AB + AC

How the Dot Product Works
Row i of A dots with Column j of B to produce element C[i][j]

Matrix A

a11
a12
a21
a22
×

Matrix B

b11
b12
b21
b22
=

Result C

c11
c12
c21
c22

Highlighted element c11 = Row 1 of A · Column 1 of B

a11×b11+a12×b21=c11
Matrix Multiplication Visual
Row of A dotted with column of B to produce one cell in C.
A matrixxB matrix=C matrix

Highlighted row from A times highlighted column from B yields C(1,1).

Understanding Matrix Multiplication

Matrix multiplication is not simply element-wise multiplication — it is a structured operation that combines rows of the first matrix with columns of the second via the dot product. This seemingly complex process is the mathematical backbone of coordinate transformations, linear systems, and virtually all of modern data science. Understanding it deeply unlocks an enormous range of applied mathematics.

The fundamental rule of matrix multiplication is dimensional compatibility: to multiply matrix A (m × n) by matrix B (n × p), the number of columns in A must equal the number of rows in B. The result is a new matrix C of size m × p. Each element C[i][j] is computed by taking row i of A and column j of B, multiplying corresponding entries pairwise, and summing the products. This is precisely the dot product of the i-th row vector of A with the j-th column vector of B.

Let's walk through a full 2×2 example step by step. Given A = [[1, 2], [3, 4]] and B = [[5, 6], [7, 8]]:

  • C[1,1] = 1×5 + 2×7 = 5 + 14 = 19
  • C[1,2] = 1×6 + 2×8 = 6 + 16 = 22
  • C[2,1] = 3×5 + 4×7 = 15 + 28 = 43
  • C[2,2] = 3×6 + 4×8 = 18 + 32 = 50

So the result is [[19, 22], [43, 50]]. Notice that the inner dimension (columns of A = rows of B = 2) "disappears" in the result: a 2×2 matrix times a 2×2 matrix yields a 2×2 matrix. More generally, an m×n matrix times an n×p matrix yields an m×p matrix — the shared dimension n is consumed by the summation process.

Matrix multiplication is associative — (AB)C = A(BC) — and distributive over addition — A(B+C) = AB+AC — but it is not commutative. In general, AB ≠ BA, and sometimes the product exists in one order but not the other (e.g., a 2×3 matrix can multiply a 3×4 matrix from the left, but not from the right). This non-commutativity reflects the fact that the order of transformations matters: rotating then scaling a coordinate system gives a different result than scaling then rotating.

Real-World Applications

Matrix multiplication is the engine behind computer graphics. Every time a 3D model is rotated, scaled, translated, or projected onto a 2D screen, the vertices of that model are being multiplied by transformation matrices. A rotation matrix R encodes a rotation in 3D space; multiplying the position vector of each vertex by R rotates the entire model. Composing multiple transformations — say, rotate then translate then project — requires only multiplying the corresponding matrices together first, then applying the single resulting matrix to every vertex. This is why GPUs are specialized matrix multiplication hardware, performing billions of matrix-vector products per second to render scenes in real time.

In machine learning, the forward pass of a neural network is dominated by matrix multiplication. Each layer of a fully-connected network takes its input vector, multiplies it by the layer's weight matrix, and adds a bias vector to produce the output for the next layer. Training adjusts these weight matrices by computing gradients via backpropagation — also a series of matrix multiplications. Modern large language models like GPT contain billions of weight parameters organized into matrices, and their inference speed is almost entirely determined by how fast the underlying hardware can multiply matrices.

Physics and quantum mechanics use matrix multiplication to describe state evolution. In quantum mechanics, physical observables correspond to matrices (operators), and measuring the expected value of an observable A in state ψ requires computing ψ†Aψ — a sequence of matrix multiplications. Transition probabilities between quantum states are encoded in transfer matrices, and raising a transfer matrix to the power n gives the probability distribution after n time steps — a computation equivalent to repeated matrix multiplication.

Economics uses Leontief input-output analysis to model how industries depend on each other. If each sector's output depends on inputs from every other sector, the entire economy can be represented as a matrix equation I = (I − A)⁻¹D, where A is the technology matrix (encoding inter-industry flows), I is the identity matrix, and D is the final demand vector. Solving this requires computing the inverse of a matrix — itself accomplished via Gaussian elimination, which is equivalent to a structured sequence of matrix multiplications. Input-output analysis is used by governments to forecast the ripple effects of policy changes, infrastructure investments, and supply chain disruptions.

Stretch, Then Shear. Or Shear, Then Stretch.

Take a square on a screen. First stretch it horizontally, then shear it to the right. Now reset and do those same two operations in the opposite order.

Same starting shape. Same two instructions. Different result.

That is matrix multiplication in one sentence. Matrices don't just hold numbers. They encode actions. And when you stack actions, order becomes part of the answer.

Each Entry Is One Dot Product

Forget the scary brackets for a second. Matrix multiplication is just repeated row-by-column dot products.

Suppose

A=[1234],B=[2015]A = \begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix}, \quad B = \begin{bmatrix}2 & 0 \\ 1 & 5\end{bmatrix}

The top-left entry of ABAB comes from the first row of AA and the first column of BB:

(1)(2)+(2)(1)=4(1)(2) + (2)(1) = 4

Do that for every row-column pairing and you get

AB=[4101020]AB = \begin{bmatrix}4 & 10 \\ 10 & 20\end{bmatrix}

That's the whole engine. No mystery. Just lots of little dot products done in a disciplined way.

The Inner Dimensions Are the Gatekeeper

Students memorize "rows times columns" and still get stuck on when multiplication is allowed. The cleaner rule is this: the inside numbers have to match.

(m×n)(n×p)(m×p)(m \times n)(n \times p) \to (m \times p)

A 2×32 \times 3 matrix can multiply a 3×43 \times 4 matrix because the 3s match. The result is 2×42 \times 4. But a 2×32 \times 3 matrix cannot multiply a 2×22 \times 2 matrix in that order. The middle numbers disagree, so the row-column pairings don't line up.

I think of it as a lock and key. The first matrix provides rows. The second provides columns. If the row length and column length don't match, there is nothing to multiply.

Why Order Matters More Than The Numbers

This is where matrix multiplication stops feeling like arithmetic and starts feeling like choreography.

Let

A=[2001],B=[1101]A = \begin{bmatrix}2 & 0 \\ 0 & 1\end{bmatrix}, \quad B = \begin{bmatrix}1 & 1 \\ 0 & 1\end{bmatrix}

Then

First ABAB

AB=[2201]AB = \begin{bmatrix}2 & 2 \\ 0 & 1\end{bmatrix}

Then BABA

BA=[2101]BA = \begin{bmatrix}2 & 1 \\ 0 & 1\end{bmatrix}

Same matrices. Different products. Which means matrix multiplication is not commutative. ABBAAB \ne BA in general.

That's not some annoying algebra exception. It's the point. In graphics, "rotate then scale" is different from "scale then rotate." In robotics, one movement changes the coordinate frame for the next. In machine learning, each layer transforms the data before handing it to the next layer. Order is part of the meaning.

The Quiet Engine Behind Search, Graphics, and AI

Matrix multiplication shows up anywhere lots of inputs need to be mixed into lots of outputs.

  • Computer graphics: rotating, scaling, and projecting 3D objects onto a 2D screen
  • Neural networks: every dense layer is a matrix multiply plus a nonlinearity
  • Economics and statistics: input-output models, regression, covariance transforms
  • Linear systems: row operations, inverses, and solution structure all live nearby

That's why matrix multiplication keeps pointing toward other ideas. Once you're comfortable with products, the next natural stops are determinants and reduced forms. Our guide on matrix determinants explains how a matrix scales area or volume, and the RREF guide shows how matrices expose whether a system actually has a solution.

Quick Questions

Why does the row-column rule work?

Because each output entry measures how one row of the first matrix combines with one column of the second. If those vectors are different lengths, the pairwise multiplication can't happen.

Can matrix multiplication ever be commutative?

Sometimes, but only in special cases. Identity matrices commute with everything. Some diagonal matrices commute with each other. Most matrices do not.

Is multiplying matrices the same as multiplying entries one by one?

No. Entrywise multiplication is a different operation. Standard matrix multiplication mixes rows and columns so it can represent composition of linear transformations.

Multiply Matrices Without Losing The Thread

Enter any compatible matrices and see the full row-by-column calculation, dimension checks, and final product in one place.

*Especially useful once the matrices are too wide to do comfortably on paper.

Frequently Asked Questions

How do you multiply two matrices?
To multiply matrices A (m×n) and B (n×p): for each element C[i][j] of the result, take row i of A and column j of B, multiply corresponding elements, and sum them. C[i][j] = Σ(A[i][k] × B[k][j]) for k from 1 to n.
When can two matrices be multiplied?
Matrices A (m×n) and B (p×q) can be multiplied only if n = p (columns of A equal rows of B). The result is an m×q matrix. Example: a 2×3 matrix times a 3×4 matrix gives a 2×4 matrix.
Is matrix multiplication commutative?
No. Matrix multiplication is NOT commutative: A×B ≠ B×A in general. If A×B is defined, B×A may not even be defined. Even when both are defined, the results are usually different.
What is the identity matrix?
The identity matrix I has 1s on the diagonal and 0s elsewhere. For any matrix A: A×I = I×A = A. It acts like the number 1 for matrix multiplication. The n×n identity matrix is denoted Iₙ.
What are the properties of matrix multiplication?
Key properties: Associative (AB)C = A(BC); Distributive A(B+C) = AB + AC; NOT commutative AB ≠ BA in general; Identity AI = IA = A; Zero A×0 = 0; Transpose (AB)ᵀ = BᵀAᵀ.
Advertisement