In short

The dot product (also called the scalar product) of two vectors \vec{a} and \vec{b} is the number \vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta, where \theta is the angle between them. In component form, \vec{a} \cdot \vec{b} = a_1b_1 + a_2b_2 + a_3b_3. It tells you how much two vectors point in the same direction, and it is the tool that lets you measure angles, compute projections, and detect perpendicularity using only algebra.

A farmer walks 5 km east carrying a heavy sack, then turns and walks 3 km northeast. At the end, she has covered 8 km of ground — but she is not 8 km from where she started. The total displacement depends on the angle between the two legs of her journey. And the amount of work she does against gravity while climbing a slope depends on the angle between her force and the direction of motion.

Angles between directions keep showing up. But vectors, as you have seen them so far, are arrows with magnitude and direction — you can add them, subtract them, scale them. None of those operations produce a single number that captures the relationship between two directions.

The dot product fills that gap. It takes two vectors and returns one number — a scalar — that encodes the angle between them. When the vectors point in the same direction, this number is large and positive. When they are perpendicular, it is exactly zero. When they point in opposite directions, it is large and negative. This single operation unlocks angle measurement, projection, and the notion of perpendicularity in any number of dimensions.

Building the idea from components

Suppose you have two vectors in the plane:

\vec{a} = a_1\hat{i} + a_2\hat{j}, \qquad \vec{b} = b_1\hat{i} + b_2\hat{j}

You already know how to add them and scale them. But what if you multiply them component by component and add the results?

a_1 b_1 + a_2 b_2

This is just a number — not a vector. At first glance, it looks arbitrary. Why multiply matching components? Why add? The answer is that this particular combination has a geometric meaning that no other combination has: it is directly related to the angle between the two vectors.

Take a specific case. Let \vec{a} = 3\hat{i} + 4\hat{j} and \vec{b} = 4\hat{i} + 3\hat{j}. Both have magnitude 5 (check: \sqrt{9 + 16} = 5). The component-wise product-and-sum gives 3 \times 4 + 4 \times 3 = 24.

Now take \vec{b} = 0\hat{i} + 5\hat{j} instead — same magnitude, but pointing straight up. The product-and-sum gives 3 \times 0 + 4 \times 5 = 20. A smaller number, because the two vectors are further apart in direction.

And if \vec{b} = -4\hat{i} - 3\hat{j} — pointing in the opposite direction to the original — the product-and-sum gives 3 \times (-4) + 4 \times (-3) = -24. Negative, because the vectors oppose each other.

The product-and-sum is tracking the angle. This operation has a name.

The vector $\vec{a} = 3\hat{i} + 4\hat{j}$ and three different choices for $\vec{b}$, all with magnitude 5. When $\vec{b}$ points close to $\vec{a}$, the dot product is large and positive (24). When $\vec{b}$ is further away in direction, the dot product is smaller (20). When $\vec{b}$ is opposite, the dot product is negative ($-24$). The dot product tracks the angle.

The definition

Dot product (scalar product)

The dot product of two vectors \vec{a} and \vec{b} is defined as

\vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta

where \theta is the angle between the two vectors when they are placed tail-to-tail, and 0 \leq \theta \leq \pi.

Equivalently, if \vec{a} = a_1\hat{i} + a_2\hat{j} + a_3\hat{k} and \vec{b} = b_1\hat{i} + b_2\hat{j} + b_3\hat{k}, then

\vec{a} \cdot \vec{b} = a_1 b_1 + a_2 b_2 + a_3 b_3

The result is a scalar (a number), not a vector. This is why it is also called the scalar product.

There are two definitions here and they must agree. That the geometric form (|\vec{a}||\vec{b}|\cos\theta) equals the component form (a_1b_1 + a_2b_2 + a_3b_3) is not obvious — it requires a proof. The proof below uses the cosine rule from trigonometry, connecting the two forms cleanly.

Why the two definitions are equivalent

Place \vec{a} and \vec{b} tail-to-tail. The vector from the tip of \vec{b} to the tip of \vec{a} is \vec{a} - \vec{b}. These three vectors form a triangle, and the cosine rule gives:

|\vec{a} - \vec{b}|^2 = |\vec{a}|^2 + |\vec{b}|^2 - 2|\vec{a}||\vec{b}|\cos\theta

Now expand the left side using components. If \vec{a} - \vec{b} = (a_1 - b_1)\hat{i} + (a_2 - b_2)\hat{j} + (a_3 - b_3)\hat{k}, then:

|\vec{a} - \vec{b}|^2 = (a_1 - b_1)^2 + (a_2 - b_2)^2 + (a_3 - b_3)^2
= a_1^2 - 2a_1b_1 + b_1^2 + a_2^2 - 2a_2b_2 + b_2^2 + a_3^2 - 2a_3b_3 + b_3^2
= (a_1^2 + a_2^2 + a_3^2) + (b_1^2 + b_2^2 + b_3^2) - 2(a_1b_1 + a_2b_2 + a_3b_3)
= |\vec{a}|^2 + |\vec{b}|^2 - 2(a_1b_1 + a_2b_2 + a_3b_3)

Compare this with the cosine rule expansion:

|\vec{a}|^2 + |\vec{b}|^2 - 2(a_1b_1 + a_2b_2 + a_3b_3) = |\vec{a}|^2 + |\vec{b}|^2 - 2|\vec{a}||\vec{b}|\cos\theta

Cancel |\vec{a}|^2 + |\vec{b}|^2 from both sides:

-2(a_1b_1 + a_2b_2 + a_3b_3) = -2|\vec{a}||\vec{b}|\cos\theta
a_1b_1 + a_2b_2 + a_3b_3 = |\vec{a}||\vec{b}|\cos\theta

The two definitions are the same thing.

Triangle formed by vectors a, b, and a minus bTwo vectors a and b placed tail-to-tail at the origin, with the difference vector a minus b connecting their tips. The angle theta is marked between a and b. This triangle is the basis for proving the equivalence of the two dot product definitions. θ a⃗ b⃗ a⃗ − b⃗
The triangle formed by placing $\vec{a}$ and $\vec{b}$ tail-to-tail. The third side is $\vec{a} - \vec{b}$. The cosine rule applied to this triangle connects the geometric definition to the component formula.

Properties of the dot product

The dot product obeys several clean algebraic rules. Each one is worth knowing and worth proving.

1. Commutative: \vec{a} \cdot \vec{b} = \vec{b} \cdot \vec{a}

From the component form: a_1b_1 + a_2b_2 + a_3b_3 = b_1a_1 + b_2a_2 + b_3a_3, since multiplication of real numbers is commutative. Alternatively, from the geometric form: |\vec{a}||\vec{b}|\cos\theta = |\vec{b}||\vec{a}|\cos\theta.

2. Distributive over addition: \vec{a} \cdot (\vec{b} + \vec{c}) = \vec{a} \cdot \vec{b} + \vec{a} \cdot \vec{c}

Write \vec{b} + \vec{c} = (b_1 + c_1)\hat{i} + (b_2 + c_2)\hat{j} + (b_3 + c_3)\hat{k}. Then:

\vec{a} \cdot (\vec{b} + \vec{c}) = a_1(b_1 + c_1) + a_2(b_2 + c_2) + a_3(b_3 + c_3)
= a_1b_1 + a_1c_1 + a_2b_2 + a_2c_2 + a_3b_3 + a_3c_3
= (a_1b_1 + a_2b_2 + a_3b_3) + (a_1c_1 + a_2c_2 + a_3c_3) = \vec{a} \cdot \vec{b} + \vec{a} \cdot \vec{c}

This is just the distributive law of real numbers, applied component by component.

3. Scalar multiplication: (k\vec{a}) \cdot \vec{b} = k(\vec{a} \cdot \vec{b})

(k\vec{a}) \cdot \vec{b} = (ka_1)b_1 + (ka_2)b_2 + (ka_3)b_3 = k(a_1b_1 + a_2b_2 + a_3b_3) = k(\vec{a} \cdot \vec{b}).

4. Dot product with itself: \vec{a} \cdot \vec{a} = |\vec{a}|^2

\vec{a} \cdot \vec{a} = a_1^2 + a_2^2 + a_3^2 = |\vec{a}|^2.

Geometrically: |\vec{a}||\vec{a}|\cos 0 = |\vec{a}|^2, since the angle between a vector and itself is 0, and \cos 0 = 1.

This property is especially useful — it lets you compute the magnitude of a vector as |\vec{a}| = \sqrt{\vec{a} \cdot \vec{a}}.

5. Dot product of perpendicular vectors: if \vec{a} \perp \vec{b}, then \vec{a} \cdot \vec{b} = 0

When \theta = \pi/2, \cos\theta = 0, so |\vec{a}||\vec{b}|\cos(\pi/2) = 0. The converse also holds (provided neither vector is zero): if \vec{a} \cdot \vec{b} = 0 and both vectors are nonzero, then \cos\theta = 0, so \theta = \pi/2 and the vectors are perpendicular.

6. Dot products of the standard unit vectors:

\hat{i} \cdot \hat{i} = \hat{j} \cdot \hat{j} = \hat{k} \cdot \hat{k} = 1
\hat{i} \cdot \hat{j} = \hat{j} \cdot \hat{k} = \hat{k} \cdot \hat{i} = 0

These follow directly from properties 4 and 5: each unit vector has magnitude 1, and any two distinct standard unit vectors are perpendicular.

Angle between two vectors

The geometric definition immediately gives you a formula for the angle between any two vectors. Rearranging \vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta:

\cos\theta = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|}

This is remarkable. Before the dot product, if someone handed you two vectors in component form — say \vec{a} = 2\hat{i} + 3\hat{j} + \hat{k} and \vec{b} = \hat{i} - \hat{j} + 4\hat{k} — you had no clean way to find the angle between them. Now you do: compute the dot product, divide by the product of magnitudes, and take the inverse cosine. Geometry reduced to arithmetic.

The formula also tells you the qualitative story at a glance, without computing the angle itself:

The sign of the dot product is a quick diagnostic. You can classify the angle as acute, right, or obtuse before ever touching a calculator.

Three cases of dot product sign: positive, zero, negativeThree pairs of vectors side by side. On the left, two vectors at an acute angle with the label dot product greater than zero. In the middle, two perpendicular vectors with the label dot product equals zero. On the right, two vectors at an obtuse angle with the label dot product less than zero. a⃗ · b⃗ > 0 acute a⃗ · b⃗ = 0 right angle a⃗ · b⃗ < 0 obtuse
The three cases of the dot product's sign. Positive means acute angle (vectors broadly agree in direction), zero means right angle (perpendicular), negative means obtuse angle (vectors broadly oppose each other).

Projection of one vector onto another

Here is the second major use of the dot product: measuring how much one vector lies along the direction of another.

Stand in sunlight with a stick held at an angle. The shadow the stick casts on the ground is shorter than the stick itself. The length of the shadow depends on the angle between the stick and the ground. That shadow-length is a projection.

Projection of vector a onto vector bVector b lies along the horizontal. Vector a starts from the same point and makes an angle theta with b. A perpendicular is dropped from the tip of a onto the line of b. The segment from the tail to the foot of the perpendicular is the projection of a onto b, with length equal to the magnitude of a times cosine theta. θ b⃗ a⃗ projection
The projection of $\vec{a}$ onto $\vec{b}$. Drop a perpendicular from the tip of $\vec{a}$ to the line of $\vec{b}$. The red segment is the projection — its length is $|\vec{a}|\cos\theta$, which equals $\frac{\vec{a} \cdot \vec{b}}{|\vec{b}|}$.

The scalar projection (or component) of \vec{a} along \vec{b} is the signed length of this shadow:

\text{comp}_{\vec{b}}\,\vec{a} = |\vec{a}|\cos\theta = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|}

The sign matters: if the projection is positive, \vec{a} has a component in the direction of \vec{b}. If negative, \vec{a} has a component in the opposite direction.

The vector projection of \vec{a} onto \vec{b} is not just the length but the actual vector along \vec{b}:

\text{proj}_{\vec{b}}\,\vec{a} = \left(\frac{\vec{a} \cdot \vec{b}}{|\vec{b}|^2}\right)\vec{b} = \left(\frac{\vec{a} \cdot \vec{b}}{\vec{b} \cdot \vec{b}}\right)\vec{b}

This formula says: take the scalar projection, divide by |\vec{b}| to get a scale factor, then multiply by \vec{b} itself. The result is a vector pointing along \vec{b} with the right length.

Why does this matter? Because projection decomposes \vec{a} into two perpendicular pieces:

\vec{a} = \text{proj}_{\vec{b}}\,\vec{a} + (\vec{a} - \text{proj}_{\vec{b}}\,\vec{a})

The first piece lies along \vec{b}. The second piece — the remainder — is perpendicular to \vec{b}. Every vector can be split this way relative to any direction. This decomposition is the reason the dot product matters in physics: resolving forces into components along a slope and perpendicular to it, or splitting a velocity into radial and tangential parts, all use this projection.

Computing the dot product — first example

Example 1: Finding the angle between two vectors

Find the angle between \vec{a} = 2\hat{i} + 3\hat{j} - \hat{k} and \vec{b} = \hat{i} - 2\hat{j} + 2\hat{k}.

Step 1. Compute the dot product.

\vec{a} \cdot \vec{b} = (2)(1) + (3)(-2) + (-1)(2) = 2 - 6 - 2 = -6

Why: multiply corresponding components and add. The negative result already tells you the angle is obtuse — the vectors point in broadly opposite directions.

Step 2. Compute the magnitudes.

|\vec{a}| = \sqrt{4 + 9 + 1} = \sqrt{14}
|\vec{b}| = \sqrt{1 + 4 + 4} = \sqrt{9} = 3

Why: you need both magnitudes for the angle formula.

Step 3. Apply the angle formula.

\cos\theta = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|} = \frac{-6}{3\sqrt{14}} = \frac{-2}{\sqrt{14}}

Why: dividing the dot product by the product of magnitudes isolates the cosine of the angle.

Step 4. Find the angle.

\theta = \cos^{-1}\left(\frac{-2}{\sqrt{14}}\right) \approx \cos^{-1}(-0.5345) \approx 122.3°

Why: the negative cosine confirms the angle is obtuse — between 90° and 180°.

Result: The angle between \vec{a} and \vec{b} is \cos^{-1}\!\left(\frac{-2}{\sqrt{14}}\right) \approx 122.3°.

The two vectors drawn from the origin in the $xy$-plane (ignoring the $z$-components for visualization). The angle between them is obtuse — you can see that they spread apart rather than pointing together, matching the negative dot product.

The negative dot product told you the angle was obtuse before you computed it. The picture confirms it: the two arrows open up past 90°.

Projection — second example

Example 2: Projecting one vector onto another

Find the projection of \vec{a} = 4\hat{i} + 3\hat{j} onto \vec{b} = 2\hat{i} + \hat{j}.

Step 1. Compute the dot product \vec{a} \cdot \vec{b}.

\vec{a} \cdot \vec{b} = (4)(2) + (3)(1) = 8 + 3 = 11

Why: you need the dot product for both the scalar and vector projection formulas.

Step 2. Compute |\vec{b}|^2.

|\vec{b}|^2 = 2^2 + 1^2 = 5

Why: the vector projection formula divides by |\vec{b}|^2, and the scalar projection divides by |\vec{b}|.

Step 3. Compute the scalar projection.

\text{comp}_{\vec{b}}\,\vec{a} = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|} = \frac{11}{\sqrt{5}} = \frac{11\sqrt{5}}{5}

Why: this is the "shadow length" — how much of \vec{a}'s magnitude lies along \vec{b}. It is positive, so \vec{a} has a component in the same direction as \vec{b}.

Step 4. Compute the vector projection.

\text{proj}_{\vec{b}}\,\vec{a} = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|^2}\,\vec{b} = \frac{11}{5}(2\hat{i} + \hat{j}) = \frac{22}{5}\hat{i} + \frac{11}{5}\hat{j}

Why: the vector projection is a vector along \vec{b} with the right length. The scale factor 11/5 applied to \vec{b} gives exactly the right arrow.

Result: The scalar projection is \frac{11\sqrt{5}}{5} \approx 4.92. The vector projection is \frac{22}{5}\hat{i} + \frac{11}{5}\hat{j}.

The vector $\vec{a} = 4\hat{i} + 3\hat{j}$ and its projection onto the direction of $\vec{b} = 2\hat{i} + \hat{j}$. The red segment from $O$ to $P$ is the vector projection. The dashed line from $A$ to $P$ is perpendicular to $\vec{b}$ — the projection decomposes $\vec{a}$ into a part along $\vec{b}$ and a part perpendicular to it.

The picture shows the decomposition: \vec{a} splits into the red projection along \vec{b} and a perpendicular remainder. The dot product made this decomposition purely algebraic — no protractor needed.

Common confusions

Going deeper

If you came here to understand what the dot product is and how to compute it, you have everything you need — you can stop here. The rest is for readers who want to see the algebraic structure, the connection to the law of cosines, and a subtlety about the definition.

The dot product as a bilinear form

The properties proved above — commutativity, distributivity over addition, and compatibility with scalar multiplication — are not just a list of useful facts. Together, they say that the dot product is a bilinear form: it is linear in each argument separately. Linearity in the first argument means:

(\alpha\vec{a} + \beta\vec{b}) \cdot \vec{c} = \alpha(\vec{a} \cdot \vec{c}) + \beta(\vec{b} \cdot \vec{c})

and commutativity gives you linearity in the second argument for free. This bilinear structure is what makes the dot product so algebraically well-behaved: you can expand dot products of sums the same way you expand products of sums of numbers.

For example, (\vec{a} + \vec{b}) \cdot (\vec{a} + \vec{b}) = \vec{a} \cdot \vec{a} + 2(\vec{a} \cdot \vec{b}) + \vec{b} \cdot \vec{b}, which gives:

|\vec{a} + \vec{b}|^2 = |\vec{a}|^2 + 2(\vec{a} \cdot \vec{b}) + |\vec{b}|^2

This is the vector version of the algebraic identity (p + q)^2 = p^2 + 2pq + q^2, and it is how the law of cosines emerges from the dot product.

The Cauchy–Schwarz inequality

From \vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta and the fact that -1 \leq \cos\theta \leq 1, you immediately get:

|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|

This is the Cauchy–Schwarz inequality. Equality holds exactly when \theta = 0 or \theta = \pi — that is, when \vec{a} and \vec{b} are parallel (pointing in the same or opposite directions). In component form, it says:

(a_1b_1 + a_2b_2 + a_3b_3)^2 \leq (a_1^2 + a_2^2 + a_3^2)(b_1^2 + b_2^2 + b_3^2)

This purely algebraic inequality — which looks like it would need pages to prove — follows in one line from the geometric interpretation of the dot product. The geometry gives you algebra for free.

Why the angle is between 0 and π

When you place two vectors tail-to-tail, there are two angles formed: one on each side, summing to 2\pi. The convention 0 \leq \theta \leq \pi picks the smaller one. This is not arbitrary — it is the only choice that makes \cos\theta uniquely determine \theta in the range [0, \pi], since \cos is strictly decreasing on this interval. Any other range would create ambiguity: is the angle 60° or 300°? The dot product does not distinguish between them (cosine is the same for both), so the convention picks the one that is well-defined.

The triangle inequality, revisited

You already know the triangle inequality: |\vec{a} + \vec{b}| \leq |\vec{a}| + |\vec{b}|. The dot product gives a clean proof. Start from |\vec{a} + \vec{b}|^2 = |\vec{a}|^2 + 2(\vec{a} \cdot \vec{b}) + |\vec{b}|^2. By Cauchy–Schwarz, \vec{a} \cdot \vec{b} \leq |\vec{a}||\vec{b}|, so:

|\vec{a} + \vec{b}|^2 \leq |\vec{a}|^2 + 2|\vec{a}||\vec{b}| + |\vec{b}|^2 = (|\vec{a}| + |\vec{b}|)^2

Taking square roots (both sides are non-negative) gives |\vec{a} + \vec{b}| \leq |\vec{a}| + |\vec{b}|. The inequality is tight (equality holds) exactly when \vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|, meaning \cos\theta = 1, meaning the two vectors point in the same direction. Geometrically: the third side of a triangle is shorter than the sum of the other two, unless the triangle is degenerate (all three vertices on a line).

Dot product in higher dimensions

Nothing in the component definition a_1b_1 + a_2b_2 + \cdots + a_nb_n requires you to stop at three dimensions. You can define the dot product of two n-dimensional vectors the same way, and all the properties — commutativity, distributivity, the Cauchy–Schwarz inequality — carry over unchanged. The geometric interpretation still holds: \cos\theta = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|} defines the angle between two vectors in \mathbb{R}^n, even when you cannot visualise it. This is how angles are measured in machine learning, data science, and quantum mechanics — through the dot product, not through a protractor.

Where this leads next

The dot product is the first of two fundamental ways to multiply vectors. The next steps: