24 November 2026 · 5 min read
What is a dot product? Explained with examples
Multiply matching numbers and add. That one move measures how much two arrows point the same way, and it runs billions of times inside every AI model.
The dot product takes two lists of numbers of the same length and gives back one number. The rule is short: multiply the numbers in matching places, then add the results.
- a = [2, 5], b = [3, −1]
- Multiply matching numbers: 2 × 3 = 6 and 5 × (−1) = −5
- Add: 6 + (−5) = 1
- So a · b = 1
What the answer tells you
Draw each list as an arrow from the origin. The dot product is large and positive when the arrows point the same way, zero when they are at right angles, and negative when they point away from each other. In symbols, a · b = |a| |b| cos θ, where θ is the angle between them.
- Same direction: cos 0° = 1, the biggest possible value.
- Right angles: cos 90° = 0, so the dot product is 0.
- Opposite: cos 180° = −1, the most negative value.
Why AI loves it
AI models store words, pictures and sounds as long vectors. To ask “how related are these two things?”, they take a dot product. Search engines use it to match your question to pages; recommendation systems use it to match you to videos; chatbots use it in attention to decide which earlier words matter for the next one.
A layer of a neural network is a matrix multiplication, which is just many dot products done at once: each output number is the dot product of the input with one row of weights.
Cosine similarity: comparing direction only
Longer vectors give bigger dot products even if the direction is the same. Dividing by both lengths removes that effect: cos θ = a · b / (|a| |b|). This is cosine similarity, and it runs from −1 (opposite) through 0 (unrelated) to 1 (same direction).
Try it: work out [1, 0] · [0, 1]. The answer, 0, tells you the two arrows are at right angles, which you can see by drawing them.
Computing one by hand
Take a = [3, −1, 2] and b = [4, 5, 1]. Line them up, multiply each pair and add. It works for any length, as long as both lists are the same length.
- 3 × 4 = 12
- (−1) × 5 = −5
- 2 × 1 = 2
- Add: 12 − 5 + 2 = 9
A positive answer means the two arrows point roughly the same way. Zero means they are at right angles. A negative answer means they point roughly in opposite directions.
The geometric meaning
The same number equals |a| × |b| × cos θ, where |a| and |b| are the lengths and θ is the angle between the arrows. So the dot product mixes two things: how long the arrows are and how closely they line up. Dividing by both lengths leaves only cos θ, which is the cosine similarity used to compare documents, songs and words.
There is a physical meaning too. Work done by a force is the dot product of the force and the distance moved: only the part of the push along the motion counts. Pushing a trolley at an angle wastes the sideways part of your effort.
Where it shows up
- Every neuron in a neural network computes a dot product of its inputs and weights.
- Search engines rank pages by the dot product between your question and each page.
- Recommendation systems match your taste vector with each film’s vector.
- Computer graphics uses it to work out how brightly light hits a surface.
Checking whether two lines are perpendicular in coordinate geometry is a dot product test: their direction vectors give zero.
Projection: the shadow picture
Shine a light straight down onto vector b and look at the shadow that vector a casts along it. The length of that shadow is a · b ÷ |b|. So the dot product measures how much of one arrow lies along the other. This picture explains why perpendicular arrows give zero: one casts no shadow on the other.
- a = [3, 4], b = [1, 0]
- a · b = 3
- |b| = 1
- Shadow length = 3, the x-part of a
A neuron is a dot product
A neuron with inputs [study hours, sleep hours] = [3, 8] and weights [0.6, 0.2] computes 3 × 0.6 + 8 × 0.2 = 3.4, then adds a bias. Every layer in a neural network is thousands of these dot products done at once, which is why matrices, being stacks of dot products, are everywhere in AI.
Properties worth knowing
- Order does not matter: a · b = b · a.
- It spreads over addition: a · (b + c) = a · b + a · c.
- A vector with itself gives its length squared: a · a = |a|².
- Scaling one vector scales the answer: (2a) · b = 2(a · b).
Glossary
- Vector: a list of numbers, drawn as an arrow.
- Magnitude: the length of a vector, √(a · a).
- Unit vector: a vector of length 1.
- Orthogonal: another word for perpendicular.
Try these yourself
- Q1. [1, 2] · [3, 4] = 3 + 8 = 11
- Q2. [2, −1] · [1, 2] = 2 − 2 = 0, so they are perpendicular
- Q3. Find k so that [k, 3] is perpendicular to [2, −4]: 2k − 12 = 0, k = 6
- Q4. Angle between [1, 0] and [1, 1]: cos θ = 1 ÷ (1 × √2), so θ = 45°
- Q5. A 10 N force at 60° moves a box 5 m: work = 10 × 5 × cos 60° = 25 J
Common mistakes
- Adding instead of multiplying the pairs first.
- Using lists of different lengths: the dot product needs matching lengths.
- Forgetting that a negative answer is allowed and meaningful.
- Mixing degrees and radians when using cos θ on a calculator.
In short
Multiply matching entries and add. The result is large when two arrows line up, zero when they are at right angles and negative when they oppose. It powers neural networks, search and physics.
Keep going
Questions people ask
What does a dot product of zero mean?
The two vectors are at right angles (perpendicular), as long as neither is the zero vector.
Is the dot product a number or a vector?
A single number, sometimes called the scalar product. The cross product, in 3D, is the one that gives a vector.
How is it different from cosine similarity?
Cosine similarity is the dot product divided by both lengths, so it ignores size and compares only direction. It always lies between −1 and 1.