When Can You Not Multiply Two Matrices?

You cannot multiply two matrices when the number of columns in the first matrix doesn’t equal the number of rows in the second matrix. This is the single rule that determines whether matrix multiplication is possible, and it applies every time, no exceptions. If matrix A is 2×3 (2 rows, 3 columns) and matrix B is 4×2 (4 rows, 2 columns), the multiplication A × B is undefined because 3 does not equal 4.

The Column-Row Rule

Matrix multiplication requires a specific alignment between the two matrices. The first matrix’s columns must match the second matrix’s rows. This is sometimes called the “inner dimensions” rule because when you write the dimensions side by side, the two inner numbers must match.

For example, if A is a 3×2 matrix and B is a 2×5 matrix, the inner dimensions are both 2, so the multiplication works. The result will be a 3×5 matrix (the “outer” dimensions). But if A is 3×2 and B is 3×5, the multiplication is impossible. There’s no way to compute it, and no workaround that preserves the original operation.

Here’s a quick reference:

  • A (2×3) × B (3×4): Valid. Inner dimensions are both 3. Result is 2×4.
  • A (2×3) × B (2×3): Not valid. Inner dimensions are 3 and 2.
  • A (5×1) × B (1×5): Valid. Inner dimensions are both 1. Result is 5×5.
  • A (1×4) × B (1×4): Not valid. Inner dimensions are 4 and 1.

Why This Rule Exists

The restriction isn’t arbitrary. It comes from how matrix multiplication actually works at the calculation level. To get a single entry in the result matrix, you take one row from the first matrix and one column from the second matrix, multiply their corresponding elements in pairs, and add those products together. This operation, called the dot product, only works when both the row and the column have the same number of elements.

If A has 3 columns, each row of A contains 3 numbers. If B has 4 rows, each column of B contains 4 numbers. You’d be trying to pair up 3 numbers with 4 numbers, and one would be left over with nothing to multiply. The math simply doesn’t produce a defined answer.

Order Matters: A × B vs. B × A

One of the most common sources of confusion is that A × B being valid does not guarantee B × A is also valid. Matrix multiplication is not commutative, and in many cases, reversing the order makes the operation impossible entirely.

Take A as a 2×3 matrix and B as a 3×5 matrix. A × B works fine and gives you a 2×5 result. But B × A asks you to multiply a 3×5 matrix by a 2×3 matrix. The inner dimensions are 5 and 2, which don’t match, so B × A is undefined.

Even when both orders are technically possible, they usually produce different results with different dimensions. If A is 2×3 and B is 3×2, then A × B gives a 2×2 matrix while B × A gives a 3×3 matrix. The only situation where A × B and B × A are both defined and the same size is when both matrices are square and share the same dimensions. Even then, the actual numbers in the result will usually differ.

Special Cases to Watch For

Square Matrices

If both matrices are square with the same dimensions (both 3×3, both 4×4, etc.), multiplication always works in both directions. The inner dimensions will always match because every dimension is the same number. This is one reason square matrices are so common in linear algebra.

Vectors

Vectors are treated as matrices with one row or one column. A row vector with 4 elements is a 1×4 matrix, and a column vector with 4 elements is a 4×1 matrix. Multiplying a 1×4 row vector by a 4×1 column vector gives a 1×1 matrix (a single number). Reversing the order, multiplying the 4×1 column vector by the 1×4 row vector, gives a 4×4 matrix. Both are valid, but they produce completely different things.

Scalar Multiplication Is Different

Multiplying a matrix by a single number (a scalar) is always valid regardless of the matrix’s dimensions. This is a different operation from matrix-by-matrix multiplication. Every element in the matrix simply gets multiplied by that number. If your calculation involves a scalar, the column-row rule doesn’t apply.

How to Fix a Dimension Mismatch

If you’re working through a problem and find that your matrices can’t be multiplied, there are a few things to check. First, verify that you have the matrices in the right order. Swapping A × B to B × A might resolve the mismatch (though it changes the mathematical meaning of what you’re computing). Second, check whether one of the matrices needs to be transposed. Transposing flips a matrix so its rows become columns and its columns become rows, changing its dimensions from m×n to n×m. In many applied problems, especially in statistics and machine learning, transposing one matrix before multiplying is a standard step.

Third, make sure you haven’t set up the matrices incorrectly. In applied contexts like systems of equations, a dimension mismatch often signals that a variable was omitted or that data was entered in the wrong orientation. The math is telling you something doesn’t line up, and the fix is usually in the problem setup rather than in forcing the multiplication to work.