Topic · Linear Algebra

Dot Product

A single number that captures how much two vectors agree in direction. It's the bridge between coordinates and geometry — multiply matching components, sum the results, and you've measured an angle, a projection, or a perpendicularity, all at once.

What you'll leave with

  • Two formulas for the dot product — one algebraic, one geometric — and the fact that they always agree.
  • An intuition for what the resulting number means: how much one vector points along another.
  • The one-line perpendicularity test: $\vec{u} \cdot \vec{v} = 0$.
  • How to recover the angle between two vectors, and how to project one onto another.

1. Two formulas, same operation

The dot product takes two vectors and returns a single number. Remarkably, it can be defined in two completely different-looking ways — one purely algebraic, one purely geometric — and they always give the same answer.

Dot product — algebraic form

For vectors $\vec{u} = (u_1, u_2, \ldots, u_n)$ and $\vec{v} = (v_1, v_2, \ldots, v_n)$ in $\mathbb{R}^n$, multiply matching components and add the results:

$$ \vec{u} \cdot \vec{v} = u_1 v_1 + u_2 v_2 + \cdots + u_n v_n = \sum_{i=1}^{n} u_i v_i $$
Dot product — geometric form

For the same two vectors, with $\theta$ the angle between them and $\|\vec{u}\|$, $\|\vec{v}\|$ their magnitudes:

$$ \vec{u} \cdot \vec{v} = \|\vec{u}\| \, \|\vec{v}\| \, \cos\theta $$

The algebraic form is what you reach for when you have coordinates: it's a handful of multiplications. The geometric form is what you reach for when you want to reason about the result — it has $\cos\theta$ in it, so the answer obviously depends on the angle.

That these two formulas agree is not obvious. It's a theorem, provable from the law of cosines applied to the triangle formed by $\vec{u}$, $\vec{v}$, and $\vec{u} - \vec{v}$. The payoff: any time you compute the algebraic form, you've implicitly learned something about the angle, and any time you reason geometrically, you can compute concretely.

A diagram of the geometric form

θ u v 2 4 6 2 4 6 0 x y u = (8, 1), v = (3, 6) u · v = 8·3 + 1·6 = 30 ‖u‖ ‖v‖ cos θ ≈ 54.08 · 0.555 ≈ 30 θ ≈ 56.3°

Both expressions evaluate to the same $30$. The first treats the vectors as lists of numbers; the second treats them as arrows in the plane. Same operation, two faces.

2. What the number measures

It's tempting to memorize the formula and move on, but the dot product has a clear meaning worth carrying around: it measures how much $\vec{u}$ points in the direction of $\vec{v}$ (scaled by the magnitudes involved).

Look again at the geometric form $\vec{u} \cdot \vec{v} = \|\vec{u}\| \|\vec{v}\| \cos\theta$. The two magnitudes are fixed by the vectors themselves — only $\cos\theta$ varies as you rotate one vector relative to the other. So the sign and size of $\vec{u} \cdot \vec{v}$ are governed by $\cos\theta$:

Angle $\theta$$\cos\theta$$\vec{u} \cdot \vec{v}$Geometric reading
$0°$ (same direction)$1$$+\|\vec{u}\|\|\vec{v}\|$ (max)Vectors agree completely
$0° < \theta < 90°$positivepositiveVectors roughly agree
$90°$ (perpendicular)$0$$0$Vectors share no direction
$90° < \theta < 180°$negativenegativeVectors roughly disagree
$180°$ (opposite)$-1$$-\|\vec{u}\|\|\vec{v}\|$ (min)Vectors point opposite ways
Mental model

If you imagine the sun directly above $\vec{v}$ casting a shadow of $\vec{u}$ onto $\vec{v}$'s line, the length of that shadow — signed, so it can be negative — is $\vec{u} \cdot \vec{v}$ divided by $\|\vec{v}\|$. The dot product is essentially the shadow, just multiplied by $\|\vec{v}\|$ so the formula is symmetric in $\vec{u}$ and $\vec{v}$.

Two consequences worth noting. First, the dot product is commutative: $\vec{u} \cdot \vec{v} = \vec{v} \cdot \vec{u}$. Both formulas make this obvious — multiplication and the angle don't care about order. Second, $\vec{u} \cdot \vec{u} = \|\vec{u}\|^2$, because the angle of a vector with itself is zero and $\cos 0 = 1$. The dot product of a vector with itself is its squared length.

3. Perpendicularity test

This is the single most-used consequence of the dot product, and it falls out of the table above:

Two nonzero vectors are perpendicular if and only if their dot product is zero.

The reasoning is a one-liner. From the geometric form, $\vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|\cos\theta$. The magnitudes are both nonzero, so the only way the product can be zero is if $\cos\theta = 0$, which happens exactly when $\theta = 90°$.

The word orthogonal is what mathematicians use instead of "perpendicular" once they're working in more than three dimensions, where you can't really picture a right angle but the algebra still works. Same idea, fancier word.

Why this matters

"Are these two directions independent?" is a question that comes up constantly — in physics (force vs. velocity), in graphics (surface normals vs. light rays), in machine learning (feature vectors vs. residuals). The dot product turns that question into a one-line numerical check.

Quick test: are $\vec{u} = (3, 4)$ and $\vec{v} = (-4, 3)$ perpendicular? Compute $\vec{u} \cdot \vec{v} = (3)(-4) + (4)(3) = -12 + 12 = 0$. Yes, they are.

4. Angle between vectors

If you can equate the two forms of the dot product, you can solve for the angle. Start from

$$ \vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|\cos\theta $$

and divide both sides by the product of magnitudes:

$$ \cos\theta = \frac{\vec{u} \cdot \vec{v}}{\|\vec{u}\|\|\vec{v}\|} $$

Apply $\arccos$ (the inverse cosine) and the angle drops out:

$$ \theta = \arccos\!\left( \frac{\vec{u} \cdot \vec{v}}{\|\vec{u}\|\|\vec{v}\|} \right) $$

This formula works in any dimension — $\mathbb{R}^2$, $\mathbb{R}^3$, or $\mathbb{R}^{1000}$. In high dimensions you can't visualize the angle, but the number $\arccos(\cdots)$ is still well-defined and still useful. (In machine learning the quantity $\cos\theta$ itself, called cosine similarity, is often what people care about — they skip the $\arccos$.)

Note

The output of $\arccos$ is always between $0°$ and $180°$ — there's no notion of a "signed" angle between two unordered vectors. If you want a signed angle (counterclockwise vs. clockwise) you need the cross product or a 2-D-specific construction, not the dot product alone.

Example: the angle between $\vec{u} = (1, 0)$ and $\vec{v} = (1, 1)$. Compute $\vec{u} \cdot \vec{v} = 1$, $\|\vec{u}\| = 1$, $\|\vec{v}\| = \sqrt{2}$. Then $\cos\theta = 1/\sqrt{2}$, so $\theta = 45°$. As expected — $(1,1)$ points along the diagonal.

5. Projections

The shadow analogy from earlier deserves to be made precise. The projection of $\vec{u}$ onto $\vec{v}$ is the vector you get by sliding $\vec{u}$ perpendicularly until it lies along $\vec{v}$'s line. It's the part of $\vec{u}$ that goes in $\vec{v}$'s direction, with the perpendicular part subtracted away.

Build it in two steps. First, the scalar component of $\vec{u}$ along $\vec{v}$ — that's the signed shadow length:

$$ \text{comp}_{\vec{v}} \vec{u} \;=\; \|\vec{u}\| \cos\theta \;=\; \frac{\vec{u} \cdot \vec{v}}{\|\vec{v}\|} $$

Then turn that into a vector by multiplying by the unit vector in $\vec{v}$'s direction, which is $\vec{v}/\|\vec{v}\|$:

$$ \text{proj}_{\vec{v}} \vec{u} \;=\; \left( \frac{\vec{u} \cdot \vec{v}}{\|\vec{v}\|} \right) \frac{\vec{v}}{\|\vec{v}\|} \;=\; \frac{\vec{u} \cdot \vec{v}}{\|\vec{v}\|^2}\,\vec{v} $$

That's the formula. The fraction $\dfrac{\vec{u} \cdot \vec{v}}{\|\vec{v}\|^2}$ is a scalar — how many copies of $\vec{v}$ fit inside the shadow — and multiplying by $\vec{v}$ packages the result as a vector pointing along $\vec{v}$.

Sanity check

If $\vec{u}$ is already parallel to $\vec{v}$, the projection should give $\vec{u}$ back. And if $\vec{u}$ is perpendicular to $\vec{v}$, the projection should be zero. Both checks fall out of the formula: parallel means $\vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|$ and the algebra collapses; perpendicular means $\vec{u} \cdot \vec{v} = 0$, killing the whole expression.

Projections are how you decompose a vector into "parallel to $\vec{v}$" and "perpendicular to $\vec{v}$" pieces: $\vec{u} = \text{proj}_{\vec{v}}\vec{u} + (\vec{u} - \text{proj}_{\vec{v}}\vec{u})$. The second piece is, by construction, orthogonal to $\vec{v}$. That decomposition underlies the Gram–Schmidt process, least-squares fitting, and a lot more.

6. Playground: the dot product geometrically

Drag the sliders for the components of $\vec{u}$ and $\vec{v}$. Watch the dot product, the angle, and the projection of $\vec{u}$ onto $\vec{v}$ react in real time. The point isn't to memorize the formulas — it's to feel how rotating one vector changes the sign of $\vec{u}\cdot\vec{v}$, how the projection shrinks as the angle approaches $90°$, and what happens at the perpendicular moment.

x y −7 −4 −1 1 4 7 7 4 1 −1 −4 −7 θ u v
Readouts
u(3.0, 1.0) v(2.0, 3.0) u · v9.00 ‖u‖3.16 ‖v‖3.61 cos θ0.79 θ37.9° projv u2.50
acute
Vector u
3.0
1.0
Vector v
2.0
3.0
Copied!
Try it

Set $\vec{u}$ to anything you like, then click Make perpendicular. The dot product snaps to $0$ and the projection vanishes — a vector with no shadow on $\vec{v}$. Now nudge $\vec{v}$ slightly off and watch the dot product creep away from zero in the direction the angle is opening.

7. Algebraic properties

The dot product satisfies a small set of identities that make it behave like a "well-mannered" multiplication — but with one big caveat. Knowing these by heart lets you simplify expressions without re-deriving from coordinates.

PropertyStatementHolds?
Commutative$\vec{u} \cdot \vec{v} = \vec{v} \cdot \vec{u}$Yes
Distributive over addition$\vec{u} \cdot (\vec{v} + \vec{w}) = \vec{u} \cdot \vec{v} + \vec{u} \cdot \vec{w}$Yes
Scalar factoring$(c\vec{u}) \cdot \vec{v} = c(\vec{u} \cdot \vec{v}) = \vec{u} \cdot (c\vec{v})$Yes
Self dot product$\vec{u} \cdot \vec{u} = \|\vec{u}\|^2 \geq 0$Yes
Associative$(\vec{u} \cdot \vec{v}) \cdot \vec{w}$No — not even defined.
Why associativity fails

$\vec{u} \cdot \vec{v}$ is a scalar, not a vector. You can't dot a scalar with a vector — the operation isn't defined. What people sometimes mean by "$(\vec{u} \cdot \vec{v})\vec{w}$" is the vector $\vec{w}$ scaled by the number $\vec{u} \cdot \vec{v}$, but that is in general a completely different vector from $\vec{u}(\vec{v} \cdot \vec{w})$ — they point in different directions. The dot product simply isn't an operation you can chain.

The first four properties combine to make the dot product a bilinear, symmetric, positive-definite form — the same structural pattern that generalizes to inner products on abstract vector spaces. Strip away the coordinates and these four identities are what's left.

8. Cauchy–Schwarz inequality

One inequality dominates the theory of dot products. It says, in coordinates,

$$ |\vec{u} \cdot \vec{v}| \;\leq\; \|\vec{u}\|\,\|\vec{v}\| $$

with equality if and only if $\vec{u}$ and $\vec{v}$ are parallel (one is a scalar multiple of the other).

Where does it come from? Directly from the geometric form: $\vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|\cos\theta$, and $|\cos\theta| \leq 1$ for every angle. Multiply both sides by the magnitudes and you have it. The maximum size of the dot product is bounded by the product of lengths; equality is the case $\cos\theta = \pm 1$, which is exactly when the two vectors lie on the same line.

Why this matters

Cauchy–Schwarz is why $\cos\theta = (\vec{u}\cdot\vec{v})/(\|\vec{u}\|\|\vec{v}\|)$ is always in $[-1, 1]$ — without the bound, $\arccos$ might receive an out-of-range input and the angle formula would be nonsense. It's also the inequality that powers the triangle inequality $\|\vec{u} + \vec{v}\| \leq \|\vec{u}\| + \|\vec{v}\|$, and a great deal of analysis and probability theory beyond.

Example: take $\vec{u} = (1, 2)$ and $\vec{v} = (3, 1)$. Then $|\vec{u} \cdot \vec{v}| = 5$, and $\|\vec{u}\|\|\vec{v}\| = \sqrt{5}\cdot\sqrt{10} = \sqrt{50} \approx 7.07$. The inequality holds with room to spare — and the slack is precisely $\|\vec{u}\|\|\vec{v}\|(1 - \cos\theta)$, which here measures how far from parallel the two vectors are.

9. Physical interpretation: work

The dot product earns its keep in physics as the formula for work — the energy transferred when a force pushes an object through a displacement.

Work done by a constant force

If a constant force $\vec{F}$ acts on an object that moves through displacement $\vec{d}$, the work done is

$$ W \;=\; \vec{F} \cdot \vec{d} \;=\; \|\vec{F}\|\,\|\vec{d}\|\cos\theta $$

where $\theta$ is the angle between the force and the displacement.

Read off the consequences from the geometric form. If the force pushes in the direction of motion ($\theta = 0°$), all of it contributes: $W = \|\vec{F}\|\|\vec{d}\|$ — maximum work. If the force pushes perpendicular to the motion ($\theta = 90°$), none of it contributes: $W = 0$. The classic example is gravity on a satellite in a circular orbit — gravity pulls toward the planet, motion is tangent to the orbit, the two are perpendicular, and gravity does no work. The satellite neither speeds up nor slows down.

And if the force opposes the motion ($\theta = 180°$, like friction on a sliding box), the work is negative: $W = -\|\vec{F}\|\|\vec{d}\|$. Negative work means energy is being removed from the object — which is exactly what friction does.

The shadow, physically

Only the component of $\vec{F}$ that points along $\vec{d}$ does work. Pulling a sled at an angle $\theta$ above horizontal? The horizontal component $\|\vec{F}\|\cos\theta$ pulls the sled forward; the vertical component just lifts a bit and does no work along the ground. The dot product packages exactly that "useful component times distance" calculation into one number.

10. Common pitfalls

Dot product is a scalar, not a vector

$\vec{u} \cdot \vec{v}$ is a single number. Don't write things like "$\vec{u} \cdot \vec{v} = (6, 9)$" — that's mixing up the dot product with component-wise multiplication. If you wanted a vector result, you wanted the cross product, the Hadamard product, or just $\vec{u} + \vec{v}$.

Magnitudes matter, not just the angle

A common reading of $\vec{u} \cdot \vec{v} = \|\vec{u}\|\|\vec{v}\|\cos\theta$ is "the dot product tells you the angle." It tells you the angle only after you divide out the magnitudes. Two pairs of vectors with the same angle but different lengths will have different dot products. If you want a pure angle measure, divide: that's why $\cos\theta = (\vec{u}\cdot\vec{v}) / (\|\vec{u}\|\|\vec{v}\|)$, not just $\vec{u} \cdot \vec{v}$.

Perpendicular means dot product = 0, not "looks like a right angle"

If your plot's $x$- and $y$-axes have different scales — a common situation in data plots — two vectors can look like they meet at $90°$ on screen while having a nonzero dot product, or vice versa. The dot product is the truth; the eyeball is not. When in doubt, compute.

Don't apply the angle formula to the zero vector

The angle formula divides by $\|\vec{u}\|\|\vec{v}\|$. If either vector is $\vec{0}$, that denominator is zero and the angle is undefined — there's no direction to take an angle to. Always check that both vectors are nonzero before reaching for $\arccos$.

11. Worked examples

Try each one yourself before opening the solution. The goal is to make these calculations automatic — the dot product is a building block that shows up in every later topic.

Example 1 · Compute $\vec{u} \cdot \vec{v}$ for $\vec{u} = (2, -1, 3)$ and $\vec{v} = (4, 5, -2)$

Step 1. Multiply matching components:

$$ (2)(4) = 8,\quad (-1)(5) = -5,\quad (3)(-2) = -6 $$

Step 2. Sum:

$$ \vec{u} \cdot \vec{v} = 8 + (-5) + (-6) = -3 $$

The negative sign tells you the angle between them is obtuse — they point more apart than together.

Example 2 · Are $\vec{u} = (1, 2, 3)$ and $\vec{v} = (4, -5, 2)$ perpendicular?

Step 1. Compute the dot product:

$$ \vec{u} \cdot \vec{v} = (1)(4) + (2)(-5) + (3)(2) = 4 - 10 + 6 = 0 $$

Step 2. The result is zero, and neither vector is the zero vector, so by the perpendicularity test:

$$ \vec{u} \perp \vec{v} \quad \checkmark $$

Yes — these two vectors are orthogonal in $\mathbb{R}^3$.

Example 3 · Find the angle between $\vec{u} = (1, 2)$ and $\vec{v} = (3, 1)$

Step 1. Dot product:

$$ \vec{u} \cdot \vec{v} = (1)(3) + (2)(1) = 5 $$

Step 2. Magnitudes:

$$ \|\vec{u}\| = \sqrt{1^2 + 2^2} = \sqrt{5},\qquad \|\vec{v}\| = \sqrt{3^2 + 1^2} = \sqrt{10} $$

Step 3. Plug into the angle formula:

$$ \cos\theta = \frac{5}{\sqrt{5}\,\sqrt{10}} = \frac{5}{\sqrt{50}} = \frac{5}{5\sqrt{2}} = \frac{1}{\sqrt{2}} $$

Step 4. Take arccos:

$$ \theta = \arccos\!\left(\tfrac{1}{\sqrt{2}}\right) = 45° $$
Example 4 · Project $\vec{u} = (3, 4)$ onto $\vec{v} = (2, 0)$

Step 1. Dot product:

$$ \vec{u} \cdot \vec{v} = (3)(2) + (4)(0) = 6 $$

Step 2. Squared magnitude of $\vec{v}$:

$$ \|\vec{v}\|^2 = 2^2 + 0^2 = 4 $$

Step 3. Apply the projection formula:

$$ \text{proj}_{\vec{v}}\vec{u} = \frac{6}{4}\,\vec{v} = \tfrac{3}{2}(2, 0) = (3, 0) $$

Makes sense: $\vec{v}$ points along the x-axis, and the part of $\vec{u} = (3, 4)$ that lies along the x-axis is exactly $(3, 0)$.

Example 5 · Verify both formulas agree for $\vec{u} = (3, 0)$ and $\vec{v} = (1, \sqrt{3})$

Algebraic form:

$$ \vec{u} \cdot \vec{v} = (3)(1) + (0)(\sqrt{3}) = 3 $$

Geometric form. Magnitudes:

$$ \|\vec{u}\| = 3,\qquad \|\vec{v}\| = \sqrt{1 + 3} = 2 $$

The angle: $\vec{u}$ points along the positive x-axis ($0°$); $\vec{v} = (1, \sqrt{3})$ makes angle $\arctan(\sqrt{3}/1) = 60°$ with the x-axis. So $\theta = 60°$ and $\cos 60° = \tfrac{1}{2}$.

$$ \|\vec{u}\|\|\vec{v}\|\cos\theta = (3)(2)(\tfrac{1}{2}) = 3 $$

Both formulas give $3$. The two definitions are consistent, as promised.

Sources & further reading

The two formulas, the perpendicularity test, the angle formula, and the projection formula are all standard linear-algebra material. The sources below are where to go for the proofs, the formal definitions, and the visual intuition this page didn't have room for.

Test your understanding

A quiz that builds from easy to hard. Pick an answer to get instant feedback and a worked explanation. Your progress is saved in this browser — come back anytime to continue.

Question 1 of 26
0 correct