Say you have A an m × n matrix and B an n × p matrix. We want to define an m × p matrix called AB such that
 (5.2) 
In other words, we want the linear transformation determined by AB to be the same as first doing a linear transformation determined by B and then when this has been done, do the linear transformation determined by A to what you got. In short, we want matrix multiplication to correspond to composition of linear functions. Then 5.2 is satisfied if and only if

Thus if we have the requirement that matrix multiplication corresponds to composition of the corresponding linear transformations, we are forced to conclude the following definition for matrix multiplication.
Definition 5.2.1 Let A be m×n and B be n×p. Then AB is n×p and the ir^{th} entry of

That is, the ir^{th} entry is the dot product of the i^{th} row of A with the j^{th} column of B.
Note that from this definition, you must have the number of columns of A equal to the number of rows of B in order to make any sense of the product. Indeed, this must be so when you consider matrix multiplication in terms of linear transformations. A linear transformation T : F^{n} → F^{m} is only defined on vectors in F^{n}.
For A and B matrices, in order to form the product, AB the number of columns of A must equal the number of rows of B.

Note the two outside numbers give the size of the product. Remember:

Example 5.2.2 Let

Then find AB. After this, find BA
Consider first AB. It is the product of a 2 × 3 and a 3 × 2 matrix and so it is a 2 × 2 matrix. The top left corner is the dot product of the top row of A and the first column of B and so forth. Be sure you can show the following.

Note that this shows that matrix multiplication is not commutative. Indeed, it can result in matrices of different size when you interchange the order. Here is a jucy little observation. If you add the entries on the main diagonal of both matrices in the above, you get the same number 13. This is the diagonal from upper left to lower right. You might wonder whether this always happens or if this is just a fluke.
Although matrix multiplication is not commutative, it does have several very important properties.
Proposition 5.2.3 If all multiplications and additions make sense, the following hold for matrices A,B,C and a,b scalars.
 (5.3) 
 (5.4) 
 (5.5) 
Proof: Using Definition ??,
Formula 5.5 is the associative law of multiplication. Using Definition ??,
Note that the claim about the associative law happens because when you have functions f,g,h such that it makes sense to take their composition in that order, we have f ∘