Multiply two matrices with step-by-step solutions. Learn matrix multiplication rules.
Auto-set to match A columns
2×2 matrices
For matrices A (m×n) and B (n×p), the product AB is defined only when:
Not commutative: AB ≠ BA (in general)
Associative: (AB)C = A(BC)
Distributive: A(B+C) = AB + AC
Matrix A
Matrix B
Result C
Highlighted element c11 = Row 1 of A · Column 1 of B
Highlighted row from A times highlighted column from B yields C(1,1).
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]]:
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.
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.
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.
Forget the scary brackets for a second. Matrix multiplication is just repeated row-by-column dot products.
Suppose
The top-left entry of comes from the first row of and the first column of :
Do that for every row-column pairing and you get
That's the whole engine. No mystery. Just lots of little dot products done in a disciplined way.
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.
A matrix can multiply a matrix because the 3s match. The result is . But a matrix cannot multiply a 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.
This is where matrix multiplication stops feeling like arithmetic and starts feeling like choreography.
Let
Then
First
Then
Same matrices. Different products. Which means matrix multiplication is not commutative. 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.
Matrix multiplication shows up anywhere lots of inputs need to be mixed into lots of outputs.
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.
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.
Sometimes, but only in special cases. Identity matrices commute with everything. Some diagonal matrices commute with each other. Most matrices do not.
No. Entrywise multiplication is a different operation. Standard matrix multiplication mixes rows and columns so it can represent composition of linear transformations.
Compute eigenvalues of square matrices (2×2, 3×3, or larger) with step-by-step explanations and characteristic polynomial solving.
Convert matrices to Reduced Row Echelon Form with step-by-step row operations. Perfect for linear algebra.
Compute 3D vector cross product with step-by-step determinant expansion, magnitude, and right-hand rule direction.