In order to multiply an matrix with n columns and m rows by a matrix with p columns and q rows, the number of columns in the first matrix must match the number of rows in the second: n= q. And the result will be a matrix having the same number of columns as the second matrix, p, and the same number of rows as the first matrix, m.

When applying a matrix to a vector i R^n, we represent the vector as a "column matrix", having 1 column and n rows. Therefore, to be able to multiply a matrix by a vector in R^n, the matrix must have n columns. In order that the result be in R^m, the matrix must have m rows.