The product of two matrices A and B is defined if the number of columns of A is equal to the number of rows of B.
In other words, for multiplication of two matrices A and B, the number of columns in A should be equal to the number of rows in B. Further more, for getting the elements of the product matrix, we take the rows of A and columns of B, multiply them element-wise and take the sum.

AB = a1b1 + a2b2 + ......... + anbn

Using the product of a row matrix and a column matrix, let us now define the multiplication of any two matrices.
If A = (aij]m × n and B =[bij]n × p are two marices of orders m × n and n × p respectively, then their product AB is the matrix of order m x p and is defined as
(AB)ij = (ith row of A) (jth column of B) for all i = 1,2, .... m and j = 1,2, ....... p

Note: If A and B are two matrices such that AB exists, then BA may or may not exist.