How to Multiply 2 Matrices: Step-by-Step Method

To multiply two matrices, you take each row of the first matrix and each column of the second matrix, multiply their corresponding entries together, and add up the results. That single number becomes one entry in your answer matrix. You repeat this for every row-column combination until the result is complete.

The process is mechanical once you see the pattern, but there’s one rule you need to check before you start.

Check That the Dimensions Are Compatible

Matrix multiplication only works when the number of columns in the first matrix equals the number of rows in the second matrix. If matrix A is 3×2 (3 rows, 2 columns) and matrix B is 2×4 (2 rows, 4 columns), the inner numbers match (both 2), so you can multiply them. The result will be a 3×4 matrix, taking its row count from A and its column count from B.

A quick way to remember: write the dimensions side by side. For A (m × n) times B (n × p), the two n’s must match. Your answer is m × p. If A is 3×2 and B is 3×2, the inner numbers are 2 and 3, which don’t match, so multiplication isn’t possible in that order.

The Row-by-Column Method

Every entry in the result matrix comes from pairing one row of A with one column of B. To find the entry in row i, column j of the result, you take row i from A and column j from B, multiply each pair of corresponding numbers, then add those products together. This operation is called a dot product.

Here’s a concrete example. Say A is a 3×2 matrix and B is a 2×3 matrix:

A = [1, 3; 4, 5; 6, 8] and B = [3, 5, 7; 2, 3, 8]

The result C will be 3×3. Let’s walk through every entry.

For the entry in row 1, column 1: take row 1 of A (1, 3) and column 1 of B (3, 2). Multiply pairs and add: 1×3 + 3×2 = 9.

For row 1, column 2: row 1 of A (1, 3) and column 2 of B (5, 3). That gives 1×5 + 3×3 = 14.

For row 1, column 3: 1×7 + 3×8 = 31.

Now row 2. Using (4, 5) from A against each column of B: 4×3 + 5×2 = 22, then 4×5 + 5×3 = 35, then 4×7 + 5×8 = 68.

Row 3 uses (6, 8): 6×3 + 8×2 = 34, then 6×5 + 8×3 = 54, then 6×7 + 8×8 = 106.

The final result:

C = [9, 14, 31; 22, 35, 68; 34, 54, 106]

This procedure works for any size matrices, as long as the dimensions are compatible. A 4×6 matrix times a 6×2 matrix means each dot product involves 6 pairs of numbers, and you end up with a 4×2 result.

A Smaller Example to Cement the Pattern

If you’re still building intuition, try a 2×2 case. Let A = [2, 1; 0, 3] and B = [4, 5; 1, 2].

  • Row 1, Column 1: 2×4 + 1×1 = 9
  • Row 1, Column 2: 2×5 + 1×2 = 12
  • Row 2, Column 1: 0×4 + 3×1 = 3
  • Row 2, Column 2: 0×5 + 3×2 = 6

Result: C = [9, 12; 3, 6]. Four entries, four dot products. For a 2×2 times 2×2, you always compute exactly 4 entries, each requiring 2 multiplications and 1 addition.

Order Matters: AB Is Not the Same as BA

Unlike regular number multiplication, matrix multiplication is not commutative. A × B and B × A generally produce different results, and in many cases one of the two isn’t even possible. If A is 3×2 and B is 2×4, then A × B gives a 3×4 matrix, but B × A would require the columns of B (4) to equal the rows of A (3), which they don’t. Even when both orders are defined (like two square matrices of the same size), the results will typically differ.

Matrix multiplication is, however, associative: (AB)C gives the same result as A(BC). It’s also distributive: A(B + C) = AB + AC. These properties become important when you’re chaining multiple operations together.

The Identity Matrix

The identity matrix is the matrix equivalent of the number 1. It’s a square matrix with 1s along the diagonal and 0s everywhere else. A 3×3 identity matrix looks like [1,0,0; 0,1,0; 0,0,1].

Multiplying any matrix by the appropriately sized identity matrix returns the original matrix unchanged. If A is m × n, then multiplying by the m×m identity on the left, or the n×n identity on the right, both give back A. This property is useful for verifying your work: if you multiply a matrix by the identity and get something different, you’ve made an error.

How It Scales With Size

For two n×n matrices, the standard method requires n³ multiplications. Doubling the matrix size means roughly 8 times the work. A 10×10 multiplication involves 1,000 individual multiplications; a 100×100 involves 1,000,000.

For large matrices, algorithms like the Strassen method reduce this by cleverly rearranging the math. Instead of 8 recursive multiplications for each 2×2 block, Strassen’s approach uses 7, bringing the growth rate down from n³ to roughly n^2.81. This matters in computing but won’t affect how you multiply matrices by hand.

Matrix Multiplication in Code

If you’re working in Python, NumPy handles matrix multiplication with three functions, each serving a different purpose:

  • np.matmul(A, B) performs standard matrix multiplication following the rules above. You can also write this as A @ B using the @ operator.
  • np.dot(A, B) works the same way for 2D arrays, but it’s a more general function that also handles dot products of 1D vectors.
  • np.multiply(A, B) does element-wise multiplication, not matrix multiplication. It multiplies each entry in A by the entry in the same position in B, which is a completely different operation.

For matrix multiplication specifically, np.matmul() or the @ operator is the clearest choice. Using np.multiply() when you meant np.matmul() is a common source of bugs.

Why Matrix Multiplication Is Everywhere

Matrix multiplication is the core operation behind much of modern computing. In machine learning, neural networks rely on it at every layer. When data passes through a fully connected layer, the network multiplies a weight matrix by the input data to produce its output. Recurrent networks (used for sequences like text and audio) and convolutional networks (used for images) both depend on the same operation.

In computer graphics, every rotation, scaling, or perspective transformation applied to a 3D object is a matrix multiplication. When you rotate a character in a video game, the software multiplies each vertex coordinate by a transformation matrix. Chaining transformations together (rotate, then scale, then translate) is just multiplying their matrices in sequence, which is why the associative property matters in practice.