Math calculator

Matrix Calculator

Every common operation, with fractions kept exact.

Matrix arithmetic

One row per line. Fractions like 1/3 are fine.

A × B

2 × 2

AB and BA are different matrices, which is the normal case. Matrix multiplication is not commutative.

A × B

The 2 by 2 result of A × B.
1922
4350

B × A — for comparison

The same two matrices multiplied the other way round. Compare it with A × B.
2334
3146

Shape

2 × 2

rows by columns

Trace

69

sum of the diagonal

AB = BA?

no

the usual case

Order matters. Nearly every identity from ordinary algebra that relies on swapping factors is false for matrices.

What this tool shows

Matrix multiplication is not commutative: AB and BA are different matrices, and usually not even the same shape. Both are shown here, because that one fact breaks most of the algebra habits carried over from ordinary numbers.

  • Addition, subtraction and scalar multiplication
  • Matrix multiplication, in both orders
  • The transpose and integer powers
  • The Hadamard and Kronecker products
  • Why the shapes have to line up
  • The trace of a square result
Eight operations Both AB and BA Exact fractions Up to 8×8

One row per line. Fractions like 1/3 are accepted and kept exact.

Updated 7 September 2026 · Works in any browser, no installation

Entry (i, j) of AB is row i of A dotted with column j of B. So an m×n times an n×p gives an m×p, and the inner dimensions have to match. Crucially, AB and BA are different matrices — often not even the same shape — so the order is part of the question, not a detail.

At a glance

Formula shown
Entry (i, j) of AB is the dot product of row i of A with column j of B, so an m×n times an n×p gives an m×p. Addition and the Hadamard product act entry by entry and need identical shapes.
Scenario support
Composing two transformations; applying a change of basis; stepping a linear system forward; working through a linear algebra exercise.
Educational estimate
Planning support from the values you enter — not professional advice.

What a matrix is for

A matrix is not primarily a grid of numbers. It is a linear transformation written down.

Multiplying a matrix by a vector applies the transformation. Multiplying two matrices composes two transformations into one — and that is where the multiplication rule comes from. It looks arbitrary until you notice it is the only rule that makes composition work.

Reading it that way makes the rest of linear algebra follow. The determinant is how much the transformation scales volume. The inverse is the transformation that undoes it. Eigenvectors are the directions it leaves pointing the same way.

It is also why the identity matrix has ones on the diagonal: that is the transformation that changes nothing.

Why order matters

AB and BA are different. Not occasionally — almost always.

Often they are not even the same shape. A 2×3 times a 3×2 gives a 2×2, and the other way round gives a 3×3. Same two matrices, results of different sizes.

The reason is composition. Rotating and then stretching is not the same as stretching and then rotating, and matrices record that faithfully. Ordinary numbers commute because scaling by 3 then by 5 is the same as 5 then 3; transformations in general are not so obliging.

The consequences reach further than they look. (A + B)² is not A² + 2AB + B², because the cross terms are AB + BA and those cannot be added into 2AB. Cancellation fails too: AB = AC does not give B = C. Almost every algebraic habit that relies on swapping factors is simply false here, which is why this page shows both orders rather than one.

Three different products

“Multiplying two matrices” can mean three different things, and mixing them up is a common source of wrong answers.

Matrix product (A × B). Rows into columns. This is the one that composes transformations, and the only one that most texts call multiplication.

Hadamard product (A ∘ B). Entry by entry, requiring identical shapes. It does not compose anything — but it is exactly what elementwise multiplication means in numerical code and in neural networks, where it is used constantly.

Kronecker product (A ⊗ B). Every entry of A replaced by that entry times the whole of B, so a 2×2 with a 3×3 gives a 6×6. It turns up in quantum computing and in signal processing, where it describes combining two independent systems.

The Hadamard product is commutative. The matrix product is not. That difference alone is a good reason to keep the names apart.

Why the shapes must match

The rules differ between operations, and the reason is not arbitrary.

Addition needs identical shapes, because it works entry by entry and there is nothing to pair a missing entry with. There is no rule that rescues a mismatch.

Multiplication needs the inner dimensions to match: an m×n times an n×p. A row of the first must have exactly as many entries as a column of the second, or the dot product has nothing to pair up.

Reading it as composition makes it obvious. B maps from a p-dimensional space to an n-dimensional one; A then maps from n dimensions onwards. If A expects a different number of dimensions than B produces, the two simply do not connect.

The result being m×p — the two outer dimensions — is the same statement: you start in p dimensions and end in m.

Where it gets used

Graphics. Every rotation, scale and translation is a matrix, and combining them into one transformation is a matrix product. A 3D scene applies several per vertex per frame.

Machine learning. A neural network layer is a matrix multiplication followed by a non-linearity. Training one is mostly very large matrix products, which is precisely what a GPU is built to do.

Systems of equations. Any linear system is Ax = b, and solving it is what most of the rest of linear algebra exists for.

Markov chains. A transition matrix raised to the nth power gives the state after n steps — which is why the power operation on this page uses binary exponentiation rather than multiplying n times.

Sources and methodology

Matrix arithmetic is standard linear algebra; these are the references.

Method. Every entry is an exact rational, so a matrix containing thirds comes back containing thirds rather than a decimal that has already lost information. Powers use binary exponentiation rather than repeated multiplication, which matters once the exponent grows: A¹² is four multiplications rather than eleven. Both AB and BA are computed for a product whenever the shapes allow, and the page reports whether they agree. That engine is verified on every change against 104 hand-written assertions, including that transposing twice returns the original matrix on three hundred generated cases, and that det(AB) equals det(A)·det(B) exactly. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

DeterminantThe determinant of any square matrix up to 8×8, exact — by fraction-free elimination rather than the cofactor expansion that becomes unusable past 4×4.
Matrix InverseThe inverse in exact fractions, with the product A × A⁻¹ displayed — and it is exactly the identity, not the identity plus rounding noise.
Row Echelon FormReduced row echelon form with every step shown, plus rank, nullity, pivot columns and a null space basis — all exact, because rank is a question about zeros.
EigenvalueEigenvalues and the characteristic polynomial up to 6×6 — the polynomial exact and the roots decimal, because roots of a polynomial are generally irrational.
System of EquationsSolve linear systems in up to six unknowns with exact fractions — row operations, the matrix form, Cramer’s rule, and the parametric family when there is no single answer.
VectorMagnitude, unit vector, sum, both products and the projection — with parallelism decided on the cross product, so exactly parallel vectors return exactly 0° and not a millionth of a degree.

More in Math, or browse all calculators.

Read the guide

What a square matrix does to area and volume — and when it collapses them — is on the Determinant Calculator.

Educational use disclaimer

This is an educational tool. Entries are kept as exact fractions, so a third stays a third rather than becoming 0.3333333.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the matrix arithmetic page showing both AB and BA for every product, since they are different matrices and often different shapes — and a page showing only one hides the fact that breaks most algebra habits carried over from ordinary numbers.
  2. Separates the three things 'multiplying two matrices' can mean: the matrix product that composes transformations, the Hadamard product that works entrywise, and the Kronecker product that combines two systems.
  3. Powers use binary exponentiation rather than repeated multiplication, so a twelfth power is four multiplications rather than eleven.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.