Two matrices can be multiplied only if their sizes are compatible. Suppose that U is an m × n matrix, and that V is a p × q matrix. In order for U•V to make sense, what must be true of the dimensions of these matrices? Although matrix multiplication uses dot products, it is common to write UV without the dot, which will be done from now on.

In order for matrix multiplication (UV) to be possible, the number of columns in the first matrix (U) must be equal to the number of rows in the second matrix (V).

So, if U is an m × n matrix, it means that it has m rows and n columns. Similarly, if V is a p × q matrix, it means that it has p rows and q columns.

For matrix multiplication to be valid, the number of columns in U (n) must equal the number of rows in V (p). Mathematically, this can be expressed as n = p.

In other words, the inner dimensions of the matrices, which correspond to the number of columns in the first matrix and the number of rows in the second matrix, must be the same.

If n is equal to p (n = p), this condition is satisfied, and the matrices U and V can be multiplied. The resulting matrix will have m rows (the same number of rows as U) and q columns (the same number of columns as V).