Shapes
A has 2 rows and 3 columns: it is 2 × 3. B is 3 × 2. You can multiply A by B only when A's columns match B's rows: 3 = 3. The result C takes A's rows and B's columns: 2 × 2.
Dot products
Each entry of C is a dot product. For row 1, column 1, pair row 1 of A with column 1 of B, multiply each pair and add: 1×7 + 2×9 + 3×11 = 7 + 18 + 33 = 58.
Keep row 1 of A and move to column 2 of B: 1×8 + 2×10 + 3×12 = 8 + 20 + 36 = 64. The answer lands where that row and that column cross: row 1, column 2 of C.
Row 2 of A works the same way. With column 1: 4×7 + 5×9 + 6×11 = 139. With column 2: 4×8 + 5×10 + 6×12 = 154. Four dot products, one per entry, fill C.
Reading the rule
In symbols, cᵢⱼ is the sum over k of aᵢₖ × bₖⱼ: row i of A slides along column j of B. If A is n × m and B is m × p, then C is n × p.
Read C by columns: column 1 of C is A times column 1 of B, a matrix times a vector. Graphics and machine learning do this constantly: a transform or a layer of weights times a column of numbers.
B times A is also allowed: B has 2 columns and A has 2 rows. But BA is 3 × 3, not 2 × 2. Even for square matrices, AB and BA are usually different, so never swap the order.
In code
In Python, three nested loops do it. i picks a row of A, j a column of B, and k walks along both, adding one product each time. Python counts from 0, so C[0][0] is c₁₁.
The innermost line runs once for every i, j and k: 2 × 2 × 3 = 12 multiplications. Two n × n matrices take n³, so doubling n makes the work 8 times bigger.
Real code calls a library. NumPy's @ operator multiplies matrices: np.array(A) @ B gives [[58, 64], [139, 154]], the same C, and it runs the loops in fast compiled code.
Try it in the Python prompt
;; step 1/10 · Check the shapes first >>> A = [[1, 2, 3], [4, 5, 6]] >>> B = [[7, 8], [9, 10], [11, 12]] >>> len(A), len(A[0]), len(B), len(B[0]) (2, 3, 3, 2)
Maths numbers rows and columns from 1, so c₁₁ is row 1, column 1. Python lists count from 0, so the same entry is C[0][0]. Matrix multiplication is associative, (AB)C = A(BC), and distributes over addition, A(B + C) = AB + AC, but it is not commutative: AB and BA usually differ.