Multiply, add, and invert matrices online for free. Plus a clear explanation of the row-by-column rule, dimension requirements, and why order matters.
Matrix multiplication combines two matrices by taking each row of the first and each column of the second, multiplying corresponding entries and summing the results. Two rules govern everything: the inner dimensions must match, and order matters A × B and B × A are usually different, and often one of them isn't even valid. Try the free Matrix Calculator → The Dimension Rule Write the dimensions side by side: (m × n) × (n × p) = (m × p) The inner numbers must match. The outer numbers give the result's size. (2×3) × (3×4) → inner 3 = 3 ✓ → result is 2×4 (3×2) × (3×4) → inner 2 ≠ 3 ✗ → undefined Put plainly: the number of columns in the first matrix must equal the number of rows in the second. Most errors in matrix work trace back to skipping this check. How Multiplication Actually Works Each entry of the result comes from one row and one column: entry (i, j) is the dot product of row i of A with column j of B. Worked example: A = [1 2] B = [5 6] [3 4] [7 8] Both are 2×2, so the result is 2×2. Position (1,1): row 1 of A × column 1 of B = (1×5) + (2×7) = 5 + 14 = 19 Position (1,2): row 1 of A × column 2 of B = (1×6) + (2×8) = 6 + 16 = 22 Position (2,1): row 2 of A × column 1 of B = (3×5) + (4×7) = 15 + 28 = 43 Position (2,2): row 2 of A × column 2 of B = (3×6) + (4×8) = 18 + 32 = 50 A × B = [19 22] [43 50] Why Order Matters Multiply the same two matrices the other way: B × A = [23 34] [31 46] Completely different result. Matrix multiplication is not commutative AB ≠ BA in general. This isn't an edge case; it's the norm. With non-square matrices it goes further: if A is 2×3 and B is 3×4, then AB is valid (2×4) while BA is undefined entirely. What does still hold: Associative: (AB)C = A(BC) Distributive: A(B + C) = AB + AC Not commutative: AB ≠ BA Addition Works Completely Differently Matrix addition is the operation people expect multiplication to be: element by element, position by position. [1 2] [5 6] [6 8] [3 4] + [7 8] = [10 12] For addition, both matrices must be exactly the same size , a 2×3 and a 3×2 cannot be added. And unlike multiplication, addition is commutative: A + B = B + A. Quick Reference Operation Dimension requirement Result size Commutative? Addition / subtraction Identical dimensions Same as inputs Yes Scalar multiplication Any Same as input Yes Matrix multiplication Columns of A = rows of B Rows of A × columns of B No Transpose Any Dimensions swapped — Inverse Square, determinant ≠ 0 Same as input — The Identity and the Inverse The identity matrix (I) has 1s down the main diagonal and 0s everywhere else. It's the matrix equivalent of the number 1: A × I = A, always. The inverse (A⁻¹) is the matrix that returns the identity: A × A⁻¹ = I. It's the closest thing to division in matrix algebra, and it's how systems of linear equations get solved. Not every matrix has one. A matrix is invertible only if it's square and its determinant is not zero . A zero determinant means the matrix is singular it collapses information in a way that can't be undone, and no inverse exists. Where This Is Actually Used Computer graphics - every rotation, scale, and translation of a 3D model is a matrix multiplication; combining several transformations means multiplying their matrices, which is exactly why order matters (rotate-then-move ≠ move-then-rotate) Machine learning - a neural network's forward pass is a chain of matrix multiplications Solving linear systems - engineering and economics problems with many simultaneous equations Cryptography - several classical ciphers are built on matrix operations Image processing - blurring, sharpening, and edge detection apply matrix kernels to pixel data Frequently Asked Questions How do you multiply two matrices? Take each row of the first matrix and each column of the second, multiply corresponding entries, and sum them the result becomes one entry in the output. The first matrix's column count must equal the second's row count. Why can't I multiply these two matrices? The inner dimensions don't match. For A (m×n) × B (n×p) to work, A's column count must equal B's row count. If A is 3×2 and B is 3×4, the multiplication is undefined. Is matrix multiplication commutative? No. AB and BA generally give different results, and with non-square matrices one may be undefined while the other is valid. Order always matters. What's the difference between matrix multiplication and element-wise multiplication? Standard matrix multiplication uses the row-by-column dot product rule. Element-wise multiplication (the Hadamard product) simply multiplies entries in matching positions and requires identical dimensions it's a different operation and gives different results. When does a matrix have no inverse? When it isn't square, or when its determinant equals zero. Such a matrix is called singular, and no inverse exists.