Matrix Multiplication Calculator

Matrix Multiplication Calculator A × B

Enter two matrices (one row per line, numbers separated by spaces or commas). The inner dimensions must match: columns of A = rows of B.

Examples:

This free matrix multiplication calculator multiplies two matrices of any compatible size and shows the result instantly, plus a worked cell so you can see exactly how each number is produced. Enter matrix A and matrix B above, press Multiply, and you get the product A×B with step-by-step logic — no sign-up, works on mobile.

What is matrix multiplication?

Matrix multiplication combines two matrices to produce a third. Unlike adding matrices — where you simply add matching entries — the matrix multiplication rule is built from the dot product: every entry of the result is the dot product of a row of the first matrix with a column of the second. This single idea powers most of modern machine learning, from the linear layers of a neural network to the projections used in principal component analysis.

Two matrices can only be multiplied when their inner dimensions match. If A is an m × n matrix and B is an n × p matrix, the product A×B exists and is an m × p matrix. The shared value n — columns of A equal to rows of B — is the hinge the whole operation turns on. If it does not hold, the product is undefined, and the calculator above will tell you so.

The rule in one line

The entry in row i, column j of the product is: (row i of A) · (column j of B) = the sum of the pairwise products across the shared dimension.

How to use the matrix multiplication calculator

The calculator is deliberately simple. Type each matrix as a block of numbers, one row per line, with values separated by spaces or commas:

  1. Enter Matrix A — for example a 2×3 matrix on two lines of three numbers.
  2. Enter Matrix B whose number of rows equals A’s number of columns.
  3. Press Multiply A × B. The product appears as a grid, with its dimensions shown above it.
  4. Open Show a worked cell to see how the top-left entry is built from a row and a column.

If the dimensions are incompatible, the tool explains precisely why — for instance, “A has 3 columns but B has 2 rows” — so you can fix the input rather than guess.

Step-by-step worked example

Suppose A is 2×3 and B is 3×2:

A = [[1, 2, 3], [4, 5, 6]] and B = [[7, 8], [9, 10], [11, 12]].

The inner dimensions match (A has 3 columns, B has 3 rows), so the product is 2×2. To find the top-left entry, take row 1 of A, [1, 2, 3], and column 1 of B, [7, 9, 11], and form the dot product:

(1)(7) + (2)(9) + (3)(11) = 7 + 18 + 33 = 58.

Repeat for every row-column pair. The complete product is [[58, 64], [139, 154]]. Notice how the two outer dimensions — the 2 rows of A and the 2 columns of B — survive into the answer, while the shared 3 disappears once it has been summed over.

Why the order matters: matrix multiplication is not commutative

With ordinary numbers, 3 × 5 equals 5 × 3. Matrices do not play by that rule. In general A×B is not equal to B×A, and often only one of the two even exists. For the example above, A×B is a 2×2 matrix, but B×A would be a 3×3 matrix — a completely different object. This non-commutativity is not a quirk; it reflects the fact that matrices represent transformations, and applying transformations in a different order genuinely gives a different result.

Matrix multiplication does obey other familiar laws. It is associative: (A×B)×C = A×(B×C). It is distributive over addition: A×(B + C) = A×B + A×C. And multiplying by the identity matrix leaves a matrix unchanged, just as multiplying a number by one does.

Matrix multiplication in Python with NumPy

Once you understand the rule, you will rarely multiply large matrices by hand. In Python, NumPy makes it a one-liner. Both the @ operator and np.dot perform true matrix multiplication:

import numpy as np
A = np.array([[1, 2, 3], [4, 5, 6]])
B = np.array([[7, 8], [9, 10], [11, 12]])
C = A @ B # or np.dot(A, B)
print(C) # [[ 58 64] [139 154]]

A common beginner trap is reaching for A * B, which in NumPy is element-wise multiplication (the Hadamard product), not matrix multiplication. It requires the two arrays to have the same shape and multiplies matching entries — a different operation entirely. When you want the linear-algebra product, use @ or np.dot. This calculator mirrors exactly what @ returns.

Where matrix multiplication shows up in machine learning

Every fully-connected layer in a neural network is a matrix multiplication: the layer takes an input vector, multiplies it by a weight matrix, and adds a bias. Stack several of these and you have the forward pass of a deep network. Batch several inputs together and the vectors become a matrix, so an entire batch is processed with a single matrix product — which is exactly why GPUs, built to multiply matrices fast, accelerated deep learning so dramatically.

Beyond neural networks, matrix multiplication appears when you rotate or scale data, compute covariance matrices, apply linear transformations in computer graphics, or chain probabilities in a Markov model. Understanding this one operation unlocks a large slice of applied mathematics.

Common mistakes to avoid
Multiplying incompatible sizes, confusing element-wise * with the matrix product, and assuming A×B equals B×A are the three errors that catch most learners. When in doubt, check the dimensions first: if the inner numbers do not match, stop.

Frequently asked questions

What size do the two matrices need to be?

The number of columns in the first matrix must equal the number of rows in the second. An m × n matrix can multiply an n × p matrix, and the result is m × p.

Can I multiply a matrix by a vector?

Yes — a vector is just a matrix with one column (or one row). Enter it as a single column of numbers and the same rule applies.

Is matrix multiplication commutative?

No. In general A×B is not equal to B×A, and frequently only one of the products is even defined.

What is the difference from element-wise multiplication?

Element-wise multiplication multiplies matching entries and needs identical shapes. Matrix multiplication uses row-by-column dot products and needs matching inner dimensions. They are different operations with different results.

Does the calculator show the steps?

Yes. Open “Show a worked cell” to see how the top-left entry of the product is formed from a row of A and a column of B.

Related linear algebra calculators

Explore the full linear algebra calculators hub, or jump to the matrix determinant calculator and the matrix transpose calculator to keep building your toolkit.