Matrix Multiplication as Composition

Why is matrix multiplication defined by that strange row-times-column recipe? Why not use the simpler entrywise product? A concrete question makes the issue vivid. If TT scales the plane and SS rotates it, what single matrix describes "first scale, then rotate"? The entrywise product of the two matrices answers no natural question at all. But a certain sum-of-products formula answers exactly this one. This article shows that matrix multiplication is not an arbitrary convention. It is forced upon us the moment we insist that matrices should represent linear maps. It is also forced once we insist that composing matrices should represent composing maps. The big picture is that linear maps are the real objects of study. Matrices are merely their coordinates once bases are chosen. This works via the isomorphism The Isomorphism L(V,W) ≅ Matrices. Function composition S∘TS \circ T is one of the most basic operations on maps. So any respectable coordinate system for maps must have a matching operation. Matrix multiplication is defined precisely so that the matrix of a composite equals the product of the matrices. No more, no less. Once this is accepted as the design goal, the formula for the (i,j)(i,j) entry of a product is not memorized. Instead it is derived from tracking how basis vectors move under Coordinate Vectors and Matrix Action. This perspective immediately explains two facts that otherwise look like arbitrary rules. Multiplication is associative because composition of functions is associative. Multiplication is generally non-commutative because composition of functions is generally non-commutative. Doing SS then TT is a different map from doing TT then SS. Associativity of matrix multiplication is often proved by a grinding index computation. But it becomes almost free once we know it mirrors composition. This article delivers a clean, motivated definition of the matrix product. It gives a full proof that this definition correctly represents composition. It also gives a separate direct proof of associativity, for comparison. It includes worked examples with genuinely asymmetric (non-square, non-commuting) matrices. It also includes a counterexample showing why matching dimensions is essential. It closes by pointing toward Invertibility of Linear Maps and Elementary Matrices and Row Operations. Both of these lean heavily on the composition viewpoint developed here.

Key takeaways
  • Matrix multiplication is defined so that M(S∘T)=M(S) M(T)\mathcal{M}(S\circ T) = \mathcal{M}(S)\,\mathcal{M}(T) for linear maps S,TS, T.
  • The (i,j)(i,j) entry of ABAB is ∑kAikBkj\sum_k A_{ik}B_{kj}, forced by tracking basis vectors through two maps in a row.
  • Dimensions must chain: an m×nm\times n matrix times an n×pn\times p matrix, matching the middle index nn.
  • Associativity (RS)T=R(ST)(RS)T = R(ST) follows instantly from associativity of function composition.
  • Non-commutativity AB≠BAAB \neq BA in general reflects that "scale then rotate" differs from "rotate then scale".
  • Key idea: matrix multiplication is composition of linear maps, written in coordinates.

Where this lives today

Matrix multiplication as composition underlies every place linear transformations are chained together. In computer graphics, a 3D object's position is transformed by successive matrices for scaling, rotation, and translation (via homogeneous coordinates), and the entire pipeline is a single matrix product precisely because applying transformations in sequence is composition. In quantum mechanics, sequential measurements or time evolutions correspond to products of operator matrices, and the physical fact that order of operations matters (non-commuting observables) is the same phenomenon as AB≠BAAB \ne BA above, now carrying deep physical content (the uncertainty principle traces back to non-commutativity of position and momentum operators). In cryptography and coding theory, linear codes and certain cipher constructions compose linear transformations over finite fields, again multiplying matrices to represent "encode, then transmit, then decode" pipelines. In statistics and machine learning, a neural network's layers are (affine or linear) maps, and the composite map of a multi-layer network is captured, layer by layer, as a product of weight matrices, with the non-commutativity of layer order being exactly why architecture (which transformation comes first) matters. In numerical analysis, factorizations like LULU or QRQR decompose one matrix as a product of simpler ones, implicitly asserting that a complicated linear map is literally a composition of easily-understood ones — an idea that leads directly to Elementary Matrices and Row Operations and to criteria for Invertibility of Linear Maps.

Ask the tutor: Can you show me why (AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1} follows directly from viewing ABAB as a composition of maps?

DefinitionMatrix product via composition

Let U,V,WU, V, W be finite-dimensional vector spaces over a field F\mathbb{F}, with ordered bases

A=(a1,…,ap) of U,B=(b1,…,bn) of V,C=(c1,…,cm) of W.\mathcal{A} = (a_1,\dots,a_p) \text{ of } U, \qquad \mathcal{B} = (b_1,\dots,b_n) \text{ of } V, \qquad \mathcal{C} = (c_1,\dots,c_m) \text{ of } W.

Let T:U→VT : U \to V and S:V→WS : V \to W be linear maps, with matrices (relative to these bases)

A=M(T)∈Fn×p,B=M(S)∈Fm×n,A = \mathcal{M}(T) \in \mathbb{F}^{n\times p}, \qquad B = \mathcal{M}(S) \in \mathbb{F}^{m\times n},

meaning

T(aj)=∑k=1nAkj bk(1≤j≤p),S(bk)=∑i=1mBik ci(1≤k≤n).T(a_j) = \sum_{k=1}^n A_{kj}\, b_k \quad (1\le j\le p), \qquad S(b_k) = \sum_{i=1}^m B_{ik}\, c_i \quad (1\le k\le n).

The matrix product BA∈Fm×pBA \in \mathbb{F}^{m\times p} is defined entrywise by

(BA)ij  =  ∑k=1nBikAkj,1≤i≤m, 1≤j≤p.(BA)_{ij} \;=\; \sum_{k=1}^n B_{ik}A_{kj}, \qquad 1\le i\le m,\ 1\le j\le p.

This is defined only when the number of columns of BB equals the number of rows of AA (both equal to nn, the dimension of the shared intermediate space VV).

Intuition

Think of a linear map as a machine that takes a vector, reads off its coordinates, and outputs new coordinates via a fixed table of instructions. If TT is such a machine turning UU-coordinates into VV-coordinates, and SS is a machine turning VV-coordinates into WW-coordinates, then bolting SS onto the output of TT builds a new machine, S∘TS \circ T, turning UU-coordinates directly into WW-coordinates. Matrix multiplication is the recipe for building the instruction table of the bolted-together machine directly from the two original tables, without ever computing an intermediate vector by hand. The reason the formula involves a sum over an index kk is that a basis vector aja_j of UU does not land on a single basis vector of VV — it lands on a combination ∑kAkjbk\sum_k A_{kj} b_k. Each of those bkb_k's is then pushed forward by SS into its own combination of cic_i's, and all these contributions to the coefficient of cic_i must be added up. The index kk ranges over the intermediate basis, which is exactly why the shared dimension nn must match: it counts the number of routes a basis vector of UU can take to reach cic_i. ```mermaid ```

Figure
Composition S∘TS\circ T traced through bases, and why the shared index must match
U (dim p=2) V (dim n=3) W (dim m=2) a₁ a₂ b₁ b₂ b₃ c₁ c₂ (BA)₁₁ = B₁₁A₁₁+B₁₂A₂₁+B₁₃A₃₁ sum runs over shared index k = 1,2,3 (dim V = n)

The mental model to keep

Every basis vector aja_j of UU fans out to all of VV's basis vectors under TT (with coefficients AkjA_{kj}), and each of those fans out again to all of WW's basis vectors under SS (with coefficients BikB_{ik}). The total coefficient of cic_i in S(T(aj))S(T(a_j)) collects one term for each intermediate route through some bkb_k, giving exactly ∑kBikAkj\sum_k B_{ik}A_{kj}. This is the entire content of the theorem below, made rigorous.

TheoremMatrix of a composition

Let U,V,WU, V, W be finite-dimensional vector spaces over a field F\mathbb{F} with ordered bases A,B,C\mathcal{A}, \mathcal{B}, \mathcal{C} as above, where dim⁡U=p\dim U = p, dim⁡V=n\dim V = n, dim⁡W=m\dim W = m. Let T∈L(U,V)T \in \mathcal{L}(U,V) and S∈L(V,W)S \in \mathcal{L}(V,W). Then the composite map S∘T∈L(U,W)S \circ T \in \mathcal{L}(U,W) satisfies

M(S∘T,A,C)  =  M(S,B,C) M(T,A,B),\mathcal{M}(S\circ T, \mathcal{A}, \mathcal{C}) \;=\; \mathcal{M}(S,\mathcal{B},\mathcal{C})\,\mathcal{M}(T,\mathcal{A},\mathcal{B}),

where matrix multiplication on the right is the product defined above, and matrices are taken with respect to the bases indicated.

Proof

Technique: direct computation of both sides against the basis A\mathcal{A}, using linearity and uniqueness of coordinate representations. Write A=M(T,A,B)∈Fn×pA = \mathcal{M}(T,\mathcal{A},\mathcal{B}) \in \mathbb{F}^{n\times p} and B=M(S,B,C)∈Fm×nB = \mathcal{M}(S,\mathcal{B},\mathcal{C}) \in \mathbb{F}^{m\times n}, so that by definition of the matrix of a linear map (see The Isomorphism L(V,W) ≅ Matrices):

T(aj)=∑k=1nAkjbkfor j=1,…,p,(1)T(a_j) = \sum_{k=1}^n A_{kj} b_k \quad \text{for } j = 1,\dots,p, \tag{1}
S(bk)=∑i=1mBikcifor k=1,…,n.(2)S(b_k) = \sum_{i=1}^m B_{ik} c_i \quad \text{for } k = 1,\dots,n. \tag{2}

Fix j∈{1,…,p}j \in \{1,\dots,p\}. Since S∘TS \circ T is linear (a composite of linear maps is linear: if f,gf,g are linear then (f∘g)(αu1+u2)=f(αg(u1)+g(u2))=αf(g(u1))+f(g(u2))(f\circ g)(\alpha u_1+u_2) = f(\alpha g(u_1)+g(u_2)) = \alpha f(g(u_1)) + f(g(u_2)) by linearity of gg then ff), we compute (S∘T)(aj)(S\circ T)(a_j) by substituting (1) into SS and using linearity of SS:

(S∘T)(aj)=S(T(aj))=S(∑k=1nAkjbk)=∑k=1nAkj S(bk),(S\circ T)(a_j) = S\big(T(a_j)\big) = S\left(\sum_{k=1}^n A_{kj} b_k\right) = \sum_{k=1}^n A_{kj}\, S(b_k),

where the last equality uses linearity of SS (additivity applied n−1n-1 times and homogeneity in each scalar AkjA_{kj}). Now substitute (2):

(S∘T)(aj)=∑k=1nAkj(∑i=1mBikci)=∑k=1n∑i=1mAkjBik ci.(S\circ T)(a_j) = \sum_{k=1}^n A_{kj} \left(\sum_{i=1}^m B_{ik} c_i\right) = \sum_{k=1}^n \sum_{i=1}^m A_{kj}B_{ik}\, c_i.

The double sum is finite, so we may swap the order of summation (commutativity and associativity of addition in F\mathbb{F}, an abelian group under addition):

(S∘T)(aj)=∑i=1m(∑k=1nBikAkj)ci=∑i=1m(BA)ij ci,(3)(S\circ T)(a_j) = \sum_{i=1}^m \left(\sum_{k=1}^n B_{ik}A_{kj}\right) c_i = \sum_{i=1}^m (BA)_{ij}\, c_i, \tag{3}

using the definition of the matrix product (BA)ij=∑kBikAkj(BA)_{ij} = \sum_k B_{ik}A_{kj} from the Definition block. On the other hand, by definition of the matrix of the linear map S∘T∈L(U,W)S \circ T \in \mathcal{L}(U,W) relative to bases A,C\mathcal{A}, \mathcal{C}, letting M=M(S∘T,A,C)M = \mathcal{M}(S\circ T,\mathcal{A},\mathcal{C}), we have by definition

(S∘T)(aj)=∑i=1mMij ci.(4)(S\circ T)(a_j) = \sum_{i=1}^m M_{ij}\, c_i. \tag{4}

Both (3) and (4) express (S∘T)(aj)(S\circ T)(a_j) as a linear combination of the basis C=(c1,…,cm)\mathcal{C} = (c_1,\dots,c_m) of WW. Since coordinates of a vector relative to a basis are unique — if ∑iαici=∑iβici\sum_i \alpha_i c_i = \sum_i \beta_i c_i then ∑i(αi−βi)ci=0\sum_i (\alpha_i-\beta_i)c_i = 0, and since C\mathcal{C} is linearly independent this forces αi=βi\alpha_i = \beta_i for every ii — we conclude

Mij=(BA)ijfor all i=1,…,m.M_{ij} = (BA)_{ij} \quad \text{for all } i = 1,\dots,m.

Since j∈{1,…,p}j \in \{1,\dots,p\} was arbitrary, Mij=(BA)ijM_{ij} = (BA)_{ij} for all i,ji,j, i.e.

M(S∘T,A,C)=BA=M(S,B,C) M(T,A,B).\mathcal{M}(S\circ T,\mathcal{A},\mathcal{C}) = BA = \mathcal{M}(S,\mathcal{B},\mathcal{C})\,\mathcal{M}(T,\mathcal{A},\mathcal{B}).

■\blacksquare

∎
CorollaryAssociativity of matrix multiplication

Let A∈Fn×pA \in \mathbb{F}^{n\times p}, B∈Fm×nB \in \mathbb{F}^{m\times n}, C∈Fl×mC \in \mathbb{F}^{l\times m}. Then

C(BA)=(CB)A.C(BA) = (CB)A.
Proof

Technique: realize each matrix as the matrix of a linear map between standard coordinate spaces, and reduce to associativity of function composition. Let U=FpU = \mathbb{F}^p, V=FnV = \mathbb{F}^n, W=FmW = \mathbb{F}^m, X=FlX = \mathbb{F}^l, each equipped with its standard basis. Standard basis vectors turn matrices into linear maps: define T:U→VT: U \to V by T(x)=AxT(x) = Ax, S:V→WS: V \to W by S(y)=ByS(y) = By, R:W→XR: W \to X by R(z)=CzR(z) = Cz. Relative to standard bases, M(T)=A\mathcal{M}(T) = A, M(S)=B\mathcal{M}(S) = B, M(R)=C\mathcal{M}(R) = C (this is the content of Coordinate Vectors and Matrix Action: the matrix of the map "multiply by AA" relative to standard bases is AA itself). By the theorem just proved, applied to the pair (S,T)(S,T):

M(S∘T)=BA.\mathcal{M}(S\circ T) = BA.

Applying the theorem again to the pair (R,S∘T)(R, S\circ T):

M(R∘(S∘T))=M(R) M(S∘T)=C(BA).\mathcal{M}\big(R\circ (S\circ T)\big) = \mathcal{M}(R)\,\mathcal{M}(S\circ T) = C(BA).

Symmetrically, applying the theorem to the pair (R,S)(R,S) gives M(R∘S)=CB\mathcal{M}(R\circ S) = CB, and applying it to the pair (R∘S,T)(R\circ S, T) gives

M((R∘S)∘T)=M(R∘S) M(T)=(CB)A.\mathcal{M}\big((R\circ S)\circ T\big) = \mathcal{M}(R\circ S)\,\mathcal{M}(T) = (CB)A.

Function composition is associative: for any functions R,S,TR,S,T with compatible domains/codomains and any u∈Uu \in U,

(R∘(S∘T))(u)=R((S∘T)(u))=R(S(T(u)))=(R∘S)(T(u))=((R∘S)∘T)(u),\big(R\circ(S\circ T)\big)(u) = R\big((S\circ T)(u)\big) = R\big(S(T(u))\big) = (R\circ S)\big(T(u)\big) = \big((R\circ S)\circ T\big)(u),

so R∘(S∘T)=(R∘S)∘TR \circ (S \circ T) = (R\circ S)\circ T as functions U→XU \to X (this uses only that ∘\circ unfolds to nested function application, no linearity needed). Hence the two matrices computed above represent the same linear map relative to the same pair of bases, and the matrix of a linear map relative to fixed bases is unique (this uniqueness is precisely the injectivity half of the isomorphism L(U,X)≅Fl×p\mathcal{L}(U,X)\cong \mathbb{F}^{l\times p} from The Isomorphism L(V,W) ≅ Matrices). Therefore

C(BA)=M(R∘(S∘T))=M((R∘S)∘T)=(CB)A.■C(BA) = \mathcal{M}\big(R\circ(S\circ T)\big) = \mathcal{M}\big((R\circ S)\circ T\big) = (CB)A. \qquad \blacksquare
∎

Worked examples

Example 1 (a genuinely non-square, non-commuting composition). Let U=F2U = \mathbb{F}^2, V=F3V = \mathbb{F}^3, W=F2W = \mathbb{F}^2, all with standard bases. Let T:U→VT: U \to V and S:V→WS: V \to W have matrices

A=M(T)=(102−103)∈F3×2,B=M(S)=(120−104)∈F2×3.A = \mathcal{M}(T) = \begin{pmatrix} 1 & 0 \\ 2 & -1 \\ 0 & 3 \end{pmatrix} \in \mathbb{F}^{3\times 2}, \qquad B = \mathcal{M}(S) = \begin{pmatrix} 1 & 2 & 0 \\ -1 & 0 & 4 \end{pmatrix} \in \mathbb{F}^{2\times 3}.

Here n=3n = 3 (the shared middle dimension) matches: AA has 33 rows, BB has 33 columns, so BABA is defined and lands in F2×2\mathbb{F}^{2\times 2}. Compute (BA)ij=∑k=13BikAkj(BA)_{ij} = \sum_{k=1}^3 B_{ik}A_{kj} entrywise:

(BA)11=1⋅1+2⋅2+0⋅0=1+4+0=5,(BA)_{11} = 1\cdot1 + 2\cdot2 + 0\cdot0 = 1 + 4 + 0 = 5,
(BA)12=1⋅0+2⋅(−1)+0⋅3=0−2+0=−2,(BA)_{12} = 1\cdot0 + 2\cdot(-1) + 0\cdot3 = 0 - 2 + 0 = -2,
(BA)21=(−1)⋅1+0⋅2+4⋅0=−1+0+0=−1,(BA)_{21} = (-1)\cdot1 + 0\cdot2 + 4\cdot0 = -1 + 0 + 0 = -1,
(BA)22=(−1)⋅0+0⋅(−1)+4⋅3=0+0+12=12.(BA)_{22} = (-1)\cdot0 + 0\cdot(-1) + 4\cdot3 = 0 + 0 + 12 = 12.

So

BA=(5−2−112).BA = \begin{pmatrix} 5 & -2 \\ -1 & 12 \end{pmatrix}.

Sanity check via the composition meaning: take u=(1,0)u = (1,0), the first standard basis vector of UU. Then

T(u)=A(10)=(120),S(T(u))=B(120)=(1⋅1+2⋅2+0⋅0−1⋅1+0⋅2+4⋅0)=(5−1).T(u) = A\begin{pmatrix}1\\0\end{pmatrix} = \begin{pmatrix}1\\2\\0\end{pmatrix}, \qquad S(T(u)) = B\begin{pmatrix}1\\2\\0\end{pmatrix} = \begin{pmatrix}1\cdot1+2\cdot2+0\cdot0 \\ -1\cdot1+0\cdot2+4\cdot0\end{pmatrix} = \begin{pmatrix}5\\-1\end{pmatrix}.

This matches column 11 of BABA, exactly as the theorem predicts: M(S∘T)\mathcal{M}(S\circ T)'s first column records the coordinates of (S∘T)(a1)=S(T(a1))(S\circ T)(a_1) = S(T(a_1)). The computation confirms the entrywise product formula is not a bookkeeping accident but literally is tracking S(T(a1))S(T(a_1)).

Example 2 (ABAB vs BABA — non-commutativity made concrete). Let S,T:F2→F2S, T : \mathbb{F}^2 \to \mathbb{F}^2 have matrices

A=(0−110)(rotation by 90∘),B=(2001)(stretch x-axis by 2).A = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} \quad (\text{rotation by } 90^\circ), \qquad B = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \quad (\text{stretch }x\text{-axis by }2).

Compute BABA ("rotate, then stretch"):

BA=(2001)(0−110)=(2⋅0+0⋅12⋅(−1)+0⋅00⋅0+1⋅10⋅(−1)+1⋅0)=(0−210).BA = \begin{pmatrix}2&0\\0&1\end{pmatrix}\begin{pmatrix}0&-1\\1&0\end{pmatrix} = \begin{pmatrix} 2\cdot0+0\cdot1 & 2\cdot(-1)+0\cdot0 \\ 0\cdot0+1\cdot1 & 0\cdot(-1)+1\cdot0 \end{pmatrix} = \begin{pmatrix} 0 & -2 \\ 1 & 0 \end{pmatrix}.

Now compute ABAB ("stretch, then rotate"):

AB=(0−110)(2001)=(0⋅2+(−1)⋅00⋅0+(−1)⋅11⋅2+0⋅01⋅0+0⋅1)=(0−120).AB = \begin{pmatrix}0&-1\\1&0\end{pmatrix}\begin{pmatrix}2&0\\0&1\end{pmatrix} = \begin{pmatrix} 0\cdot2+(-1)\cdot0 & 0\cdot0+(-1)\cdot1 \\ 1\cdot2+0\cdot0 & 1\cdot0+0\cdot1 \end{pmatrix} = \begin{pmatrix} 0 & -1 \\ 2 & 0 \end{pmatrix}.

Indeed BA≠ABBA \neq AB. Trace the vector e1=(1,0)e_1 = (1,0) through each order to see why, geometrically: under BABA, e1↦(0,1)e_1 \mapsto (0,1) (rotate e1e_1 to (0,1)(0,1), then stretching the xx-axis does nothing to it since its xx-coordinate is 00). Under ABAB, e1↦(0,2)e_1 \mapsto (0,2) (stretch e1e_1 to (2,0)(2,0), then rotating sends (2,0)(2,0) to (0,2)(0,2)). Stretching before rotating versus after gives different final lengths, because the stretch treats the xx-axis specially and rotation moves points off that axis. This is the concrete meaning of non-commutativity: composing functions in different orders produces different functions.

Counterexamplewhy matching inner dimensions cannot be dropped

Suppose we try to define a "product" of B∈Fm×nB \in \mathbb{F}^{m\times n} and A∈Fr×pA \in \mathbb{F}^{r\times p} whenever n≠rn \neq r, say by padding with zeros or simply pairing up entries mismatched in index. Concretely, take

B=(12)∈F1×2,A=(10−1213041)∈F3×3.B = \begin{pmatrix} 1 & 2 \end{pmatrix} \in \mathbb{F}^{1\times 2}, \qquad A = \begin{pmatrix} 1 & 0 & -1 \\ 2 & 1 & 3 \\ 0 & 4 & 1 \end{pmatrix} \in \mathbb{F}^{3\times 3}.

Here BB has 22 columns but AA has 33 rows, so n=2≠3n=2 \ne 3. There is no linear map S:F1→F?S:\mathbb{F}^1\to\mathbb{F}^? built from BB whose domain matches the codomain of the map built from AA: AA represents a map T:F3→F3T:\mathbb{F}^3 \to \mathbb{F}^3, while BB represents a map S:F2→F1S: \mathbb{F}^2 \to \mathbb{F}^1. The composite S∘TS \circ T is not even defined as a function, since the outputs of TT live in F3\mathbb{F}^3 but SS only accepts inputs from F2\mathbb{F}^2. Any formula one invents for "BABA" in this mismatched case — e.g., truncating AA to its first two rows before multiplying, giving (1⋅1+2⋅21⋅0+2⋅11⋅(−1)+2⋅3)=(525)\begin{pmatrix}1\cdot1+2\cdot2 & 1\cdot0+2\cdot1 & 1\cdot(-1)+2\cdot3\end{pmatrix} = \begin{pmatrix}5 & 2 & 5\end{pmatrix} — is not the matrix of any composition S∘TS \circ T, because that composition does not exist. Such a formula might still be "computable," but it represents nothing; it fails the entire design goal of the Definition, namely that M(S∘T)=M(S)M(T)\mathcal{M}(S\circ T) = \mathcal{M}(S)\mathcal{M}(T). This is exactly why the Definition insists the number of columns of BB equal the number of rows of AA: this shared number nn is the dimension of the intermediate space VV, without which "compose SS after TT" is meaningless. Dropping the dimension-matching hypothesis does not merely make the proof harder — it removes the object being proved about.

Scope, edge cases & common traps

SituationWhat happensWhy
AA is n×pn\times p, BB is m×nm \times nBABA defined, size m×pm\times pshared index nn = dim of intermediate space
AA is n×pn\times p, BB is m×qm\times q, q≠nq\ne nBABA undefinedno linear map to compose (see counterexample)
A,BA, B both n×nn\times nboth AB,BAAB, BA defined, same sizebut generally AB≠BAAB \ne BA (Example 2)
AA is 1×n1\times n (row), BB is n×1n\times 1 (column)ABAB is 1×11\times1 scalar, BABA is n×nn\times norder changes even the shape of the answer
Composing 33 or more mapsproduct is unambiguous, any grouping worksassociativity (Corollary), inherited from function composition

The mathematician behind it

Arthur Cayley, working in the mid-1800s, is credited with the first systematic treatment of matrices as objects in their own right, including the definition of matrix multiplication designed exactly to mirror composition of the linear substitutions (what we would now call linear maps) that matrices encode. Cayley's 1858 Memoir on the Theory of Matrices introduced matrix algebra abstractly, proved the Cayley–Hamilton theorem for small cases, and explicitly remarked that matrix multiplication corresponds to compounding linear substitutions — the same insight this article makes rigorous with modern coordinate-vector language.

Origins · 1 minArthur Cayley and how this was discovered
AC
Arthur Cayley
1821–1895 · Victorian algebra and the birth of matrix theory

Cayley was a prolific English mathematician who, alongside legal work as a barrister, produced over 900 papers spanning algebra, geometry, and invariant theory. His matrix memoir treated arrays as single algebraic entities obeying their own laws, deliberately built so that multiplying matrices would correspond to composing the linear substitutions they represented — the exact motivating idea behind the Definition given here.

History
- 1858 — Cayley publishes A Memoir on the Theory of Matrices, treating matrices as algebraic objects and defining their multiplication to mirror composition of linear substitutions.
- 1855 — Hamilton's quaternion algebra (non-commutative multiplication) circulates and influences Cayley's willingness to accept AB≠BAAB \neq BA as unremarkable.
- 1870s–1890s — Frobenius and others systematize matrix rank, determinants, and the theory of linear transformations building on Cayley's algebra.
- 1900s–1920s — Abstract linear algebra (vector spaces, linear maps) crystallizes, recasting matrix multiplication explicitly as composition once bases are fixed.
- 1930s–present — the coordinate-free viewpoint (maps first, matrices as coordinates) becomes standard in textbooks, the framing used throughout this article.
Why isn't matrix multiplication just the entrywise product of two matrices?

The entrywise product is a perfectly valid operation (the Hadamard product), but it does not correspond to composing linear maps. If AA and BB are matrices of linear maps TT and SS, tracking what happens to a basis vector aja_j as it passes through TT and then SS naturally produces the sum-of-products formula ∑kBikAkj\sum_k B_{ik}A_{kj}, not an entrywise product. Matrix multiplication is defined to solve the specific problem of representing composition in coordinates; the entrywise product solves a different (also useful, but unrelated) problem, such as combining independent per-coordinate scalings.

Do I need to check that both ABAB and BABA are defined before asking whether AB=BAAB=BA?

Yes. If AA is m×nm\times n and BB is n×mn\times m with m≠nm \ne n, then ABAB is m×mm\times m while BABA is n×nn\times n — different sizes entirely, so they cannot be equal (they are not even comparable). Only when AA and BB are both square of the same size n×nn\times n does it make sense to ask whether AB=BAAB=BA, and even then the answer is usually no, as Example 2 shows with a rotation and a stretch.

Is matrix multiplication ever commutative?

Yes, in special cases: the identity matrix commutes with everything, scalar multiples of the identity commute with everything, and any matrix commutes with itself and its own powers. More generally, two matrices representing linear maps that are "simultaneously diagonalizable" (share an eigenbasis) commute. But for generic matrices, especially those representing geometrically different operations like rotation and non-uniform scaling, commutativity fails, as shown in Example 2.

Does associativity mean I can multiply matrices in any order I like?

No — associativity only says that the grouping of consecutive multiplications does not matter: (CB)A=C(BA)(CB)A = C(BA). It does not say you may swap the order of the factors; CBACBA computed strictly left to right or right to left with the same left-to-right sequence gives one unambiguous answer, but ACBACB or BCABCA (permuted factors) are generally completely different matrices. Associativity licenses dropping parentheses; it does not license commuting factors.

Why does the shared dimension have to be exactly the dimension of the intermediate vector space?

Because that dimension counts how many basis vectors of the intermediate space VV exist, and the entry (BA)ij=∑kBikAkj(BA)_{ij} = \sum_k B_{ik}A_{kj} sums over exactly those basis vectors — the "routes" a vector can take from UU to WW via VV. If the matrices did not agree on this count, there would be no consistent way to assign a route index kk to both factors simultaneously, which is precisely the failure illustrated in the counterexample block.

How does this relate to invertibility of linear maps?

If S:V→WS: V \to W and T:W→VT: W \to V satisfy S∘T=idWS \circ T = \mathrm{id}_W and T∘S=idVT \circ S = \mathrm{id}_V, then by the theorem here, M(S)M(T)=I\mathcal{M}(S)\mathcal{M}(T) = I and M(T)M(S)=I\mathcal{M}(T)\mathcal{M}(S) = I, exactly the definition of M(T)\mathcal{M}(T) being the inverse matrix of M(S)\mathcal{M}(S). Composition is thus the conceptual bridge connecting invertible linear maps to invertible matrices, a connection developed fully in Invertibility of Linear Maps.

Why do elementary row operations correspond to left-multiplication by special matrices?

An elementary row operation on a matrix AA can itself be realized as a linear map EE applied to the columns of AA viewed as vectors, i.e., as composing AA (as a map) with EE first. By the theorem here, performing the row operation is the same as replacing AA with M(E)A\mathcal{M}(E)A for the appropriate elementary matrix M(E)\mathcal{M}(E). This is exactly the perspective developed in Elementary Matrices and Row Operations, and it is only sensible because matrix multiplication was built to represent composition in the first place.

Before this

Where this leads