Why Does Matrix Multiplication Depend on Order?

Introduction

Matrix multiplication depends on order because a matrix can represent a transformation, and performing one transformation before another may produce a different result from reversing them. The multiplication rule reflects that sequence: in the product AB, B acts first and A acts second. The numbers and dimensions matter too, so AB may exist even when BA does not. Understanding these points makes a seemingly unusual rule much easier to follow.

What matrix multiplication does

A matrix is a rectangular arrangement of numbers. It can store data, describe equations, or represent a rule that changes a vector. A vector is an ordered list of numbers, often pictured as an arrow. For example, a two-number vector can represent a point or direction in a flat plane.

To multiply two matrices, each entry in the result is calculated from a row of the first matrix and a column of the second. Multiply corresponding numbers in that row and column, then add the products. This is called a dot product.

For a simple example, let A have one row, [1, 2], and let B have one column, [3, 4]. Their product is the single number 1 × 3 + 2 × 4, which equals 11. The row and column must have the same number of entries for this calculation to work.

More generally, if A has r rows and c columns, and B has c rows and s columns, then AB is defined and has r rows and s columns. The matching inner dimensions, c and c, make the row-by-column calculations possible.

Why reversing the order can change the result

In ordinary arithmetic, multiplying two numbers gives the same result in either order: 3 × 5 equals 5 × 3. Matrices are different. The product AB is generally not equal to BA, even when both products can be calculated. This property is called noncommutativity: changing the order of operations can change the outcome.

Here is a small example:

A = [[1, 1], [0, 1]]
B = [[1, 0], [1, 1]]

Calculating each product gives:

AB = [[2, 1], [1, 1]]
BA = [[1, 1], [1, 2]]

Both products are defined, but their entries differ. The multiplication rule has not changed; the rows and columns being paired have changed. In AB, entries come from rows of A and columns of B. In BA, rows of B are paired with columns of A instead.

This example shows that order matters, but it does not mean that every pair of matrices produces different results when reversed. Some matrices commute, meaning AB = BA. The identity matrix, which leaves a vector unchanged, commutes with every compatible square matrix. Certain other pairs commute as well. Commuting is a special case, not a general rule.

The connection to transformations

The clearest way to understand order is to think of matrices as instructions for transforming vectors. A matrix may rotate, stretch, reflect, or shear a vector. A shear shifts parts of a shape in a slanted direction while preserving straight, parallel lines.

When matrices are applied to a vector in a product such as ABx, the rightmost matrix acts first. In this expression, B changes x first; then A acts on the result. Matrix multiplication is arranged this way so that the combined product AB represents the complete sequence of transformations.

For example, imagine first rotating a shape and then stretching it more in one direction than another. The outcome may differ from stretching it first and rotating it afterward. After the stretch, the shape has a new orientation and proportions, so the later rotation acts on a different result than it would have before the stretch.

Not every pair of transformations changes the outcome when reversed. A uniform stretch that enlarges every direction by the same factor does not alter the direction of a vector. Combining this kind of scaling with a rotation can produce the same result in either order. By contrast, a directional stretch and a rotation generally do not commute.

This is why multiplication order is not just a convention for arranging numbers. It records the order in which transformations act. Reversing the matrices can mean carrying out a different sequence, and a different sequence can change the final vector or shape.

Why dimensions can prevent reversing the order

There is another reason the order matters: the two products may not both be possible. Suppose A has 2 rows and 3 columns, while B has 3 rows and 4 columns. AB is defined because the number of columns in A matches the number of rows in B. Its result has 2 rows and 4 columns.

But BA would try to multiply a 3-by-4 matrix by a 2-by-3 matrix. The inner dimensions, 4 and 2, do not match, so that product is undefined. In this situation, it is not accurate to say that AB is different from BA; BA cannot be formed under the standard multiplication rule.

Even when both orders are defined, their dimensions may differ. For instance, if A is 2-by-3 and B is 3-by-2, then AB is 2-by-2, while BA is 3-by-3. Matrices of different sizes cannot be equal, so these products must be distinct.

A practical way to calculate a product

For a small matrix multiplication, keep the order visible and work through one result entry at a time. Take the row from the left-hand matrix and the column from the right-hand matrix, multiply matching entries, and add them.

For example, the top-left entry of AB uses the first row of A and the first column of B. The top-right entry uses the first row of A and the second column of B. Continue this pattern for each row and column in the result.

Before calculating, check that the number of columns in the left matrix equals the number of rows in the right matrix. Then check the result’s size: it will have as many rows as the left matrix and as many columns as the right matrix. These checks help catch common errors, including accidentally reversing the factors.

It is also useful to test the product on a vector when the matrices represent transformations. Compare what happens when B acts first and A second with what happens when A acts first and B second. This gives the abstract multiplication rule a concrete interpretation.

Where order matters in applications

Computer graphics uses matrices to describe changes to points and shapes, such as rotation, scaling, and movement. A graphics program may combine several transformations into one matrix. Their order determines how the original points are changed. For example, rotating an object around its own center is not generally the same as moving it and then rotating it around a different origin.

Systems of linear equations also use matrix products. Matrices can represent relationships between sets of numbers, and combining them can describe the effect of applying one relationship after another. Keeping the factors in the intended order is essential to preserving what each operation means.

In data analysis and other computational fields, matrices can represent transformations between collections of values. A product may combine stages of a calculation, with each stage acting on the output of the previous one. Reversing the factors can change the calculation or make it impossible because the dimensions no longer match.

Common misunderstandings

“Multiplication is always commutative.” This is true for ordinary numbers but generally false for matrices. Always check whether the order can be reversed rather than assuming it can.

“AB means A acts first.” When the product is applied to a column vector as ABx, B acts first because it is closest to the vector. A acts on the result afterward.

“If both products exist, they have the same size.” Not necessarily. A and B can have shapes that allow both AB and BA while producing different-sized results.

“Different order always means a different answer.” It usually does, but some matrices commute. The safe conclusion is that reversing the order can change the result and must be checked.

Conclusion

Matrix multiplication depends on order because each matrix combines numbers in a particular row-and-column pattern and can represent a transformation applied in sequence. In a product AB, B acts first on a vector, followed by A. Reversing the factors may change the result, change its dimensions, or make the product undefined. Some pairs commute, but that is a special case worth verifying rather than assuming.