Network Architecture Intermediate

Matrix Multiplication

Pairing up rows and columns, multiplying each pair, then summing

Key points
  • Matrix multiplication is a calculation that lays two tables on top of each other and produces a new one. Each row is paired with each column, multiplied piece by piece, and summed into a single cell.
  • Passing through one layer of a neural network is exactly this calculation. A row of incoming numbers meets a column of weights and becomes one number in the next layer.
  • Almost everything an AI does is this multiply-and-add step, repeated. The math itself is easy — it's the staggering number of repeats that's hard.
  • Every cell's calculation is independent of every other cell, so the work can be split up and handed out all at once. That's why AI needs a GPU.
  • Not any two tables can be multiplied. The width of the first table has to match the height of the second before they can be paired up.
Contents

1The analogy

You've placed one big snack order for the whole class from the corner food stall. You're holding two sheets of paper. One is the order sheet — each row belongs to one student, and lists how many dumplings and how many spring rolls that student ordered. The other is the price sheet — one column holds each item's price, and the column beside it holds its calories.

Now you work out what each student owes. Point at that student's row on the order sheet with one hand, and the price column on the price sheet with the other. Multiply the dumpling count by the dumpling price, multiply the spring-roll count by the spring-roll price, and add those two products together. Write the sum in one cell of a fresh sheet.

Move your fingers through every row and every column until all the cells are filled, and a brand-new sheet appears. That work is matrix multiplication.

2In detail

Filling in a single cell

Filling one cell in the new sheet only takes two rows — sorry, one row from the first table and one column from the second. Multiply the first entry of each together, multiply the second entries together, keep going to the end, then add up everything you just multiplied. That sum is the number that goes in the cell.

So the new table's height matches the row count of the first table, and its width matches the column count of the second. Thirty students, two things to work out — price and calories — gives a result with thirty rows and two columns.

Filling one cell takes as many multiplications as the length of the paired row and column. Five menu items means five multiplications and four additions. The arithmetic itself is grade-school level. What makes it hard is how many cells there are to fill.

One layer of a neural network is exactly this

A neural network takes in a row of numbers and turns it into a different row of numbers. That conversion is matrix multiplication. The incoming row is the order sheet's row, and the layer's weights are the price sheet. One column of the weight table produces one cell of the next layer.

The numbers sitting in the weight table were set during training. Once training ends, that table is fixed. Every time we send in a question, all the model does is push a new row of numbers through that same table.

A hundred layers means this pass repeats a hundred times, each result table feeding the next as its input. Attention, and image-model convolutions, all boil down to the same multiply-and-add at different shapes when you look inside them.

Easy math, terrifying repeat count

A model with billions of weights means a price sheet with billions of cells. Every piece of text has to pass through those cells at least once, so producing a single line of an answer sets off multiplications and additions numbering in the trillions.

One person with a calculator would need a lifetime. That's why AI stories always come bundled with talk of compute and electricity bills. Push performance up by adding layers and widening the tables, and the multiplication count grows even faster.

Cells don't talk to each other, so GPUs work

Luckily, this calculation has one convenient property. No cell in the new table waits on the result of any other cell. Whoever is filling in the top-left cell never needs to compare notes with whoever is filling in a cell three rows down.

That means the work can be handed to thousands of calculators at once. That's exactly what a GPU does — not a device that's clever at hard math, but one built to do easy math many times at once. Graphics memory capacity is often the bottleneck too, because the whole table has to be loaded onto it at once.

The shapes have to match

If the order sheet has five columns but the price sheet only has four rows, one column is left without a partner. That's why the width of the first table must always equal the height of the second.

Matching table sizes across layers is a big part of designing a model. The order matters too — you can't swap the tables freely. Multiplying the order sheet by the price sheet gives a different result than multiplying the price sheet by the order sheet, when it's even possible at all.

3More precisely

A matrix is a grid of numbers arranged in rows and columns, and matrix multiplication pairs each row of the first matrix with each column of the second, multiplies matching entries, sums them, and places the result at the corresponding position. The order of multiplication can't be swapped, but how the multiplications are grouped can be, which is why several layers can sometimes be pre-combined into one as an optimization.

The analogy breaks down in a few places. At the food stall every value is positive and has a clear unit, but a neural network's weights are often negative and carry no units — summed products can cancel each other out. Real models also don't process one student at a time; they stack many order sheets into one and push them through together, a bundle called a batch. An activation function also sits between layers, adding a bend that multiplication alone can't produce. Without it, stacking layers would collapse right back down to a single table.

One more difference is scale. A food stall's order sheet fits comfortably on one page, but a real weight table can hold billions of cells, so the matrices involved are usually described by their shape alone — height and width — rather than written out in full.

4Try it yourself

5Common misconceptions

  • It's easy to think matrix multiplication multiplies matching cells one by one, but actually a whole row is paired with a whole column, multiplied entry by entry, and summed into one cell.

  • It's easy to think very complicated math runs inside an AI, but actually it's almost entirely multiplication and addition — what's unimaginable is only how many times it repeats.

  • It's easy to think a GPU is just smarter than a CPU, but actually it's built to run huge numbers of simple, unrelated calculations at the same time.

7One-line summary

In shortMatrix multiplication pairs rows with columns, multiplies and sums them into a cell, and everything an AI does is this same calculation repeated an enormous number of times.

Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02