Skip to content
  • Open the math solver
  • Ask the AI tutor
  • Find an AP course
  • Create a quiz
  • Open the calculator
  • Graphing Calculator
  • Browse all calculators
  • Read math guides
↑ ↓Enter to open · Esc to close
Solve a problem

Linear Algebra

The Dot Product Explained

By MathSolver Pro Editorial Team · Published

The dot product combines two vectors into a single number that measures how much they point in the same direction. It is the tool for finding angles between vectors, checking perpendicularity, projecting one vector onto another and computing work in physics.

The component formula

The dot product, also called the scalar product, takes two vectors of the same length and returns a single number, not a vector. To compute it, multiply matching components and add the results:

a⋅b=a1b1+a2b2+⋯+anbn\mathbf{a} \cdot \mathbf{b} = a_1b_1 + a_2b_2 + \cdots + a_nb_n

Example 1: a dot product in three dimensions

  1. Let a=(2,−1,3)\mathbf{a} = (2, -1, 3) and b=(4,0,−2)\mathbf{b} = (4, 0, -2).
  2. Multiply matching components: 2⋅4=82 \cdot 4 = 8, (−1)⋅0=0(-1) \cdot 0 = 0 and 3⋅(−2)=−63 \cdot (-2) = -6.
  3. Add: a⋅b=8+0−6=2\mathbf{a} \cdot \mathbf{b} = 8 + 0 - 6 = 2.

The formula works in any number of dimensions, which is why the dot product is so common in data science, where vectors may have thousands of components. It is also the building block of matrix multiplication: every entry of a matrix product is the dot product of a row with a column.

The geometric formula and the angle between vectors

The dot product has a second, geometric description. If θ\theta is the angle between the two vectors when they are drawn from the same point, then:

a⋅b=∣a∣ ∣b∣cos⁡θ\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}|\,|\mathbf{b}|\cos\theta

Here ∣a∣|\mathbf{a}| is the length, or magnitude, of a\mathbf{a}. The two formulas always agree, a fact that follows from the law of cosines applied to the triangle formed by a\mathbf{a}, b\mathbf{b} and a−b\mathbf{a} - \mathbf{b}. Combining them gives a practical way to find the angle between any two vectors:

cos⁡θ=a⋅b∣a∣ ∣b∣\cos\theta = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}|\,|\mathbf{b}|}

Example 2: finding an angle

  1. Let a=(1,2,2)\mathbf{a} = (1, 2, 2) and b=(2,−1,2)\mathbf{b} = (2, -1, 2).
  2. a⋅b=2−2+4=4\mathbf{a} \cdot \mathbf{b} = 2 - 2 + 4 = 4.
  3. ∣a∣=1+4+4=3|\mathbf{a}| = \sqrt{1 + 4 + 4} = 3 and ∣b∣=4+1+4=3|\mathbf{b}| = \sqrt{4 + 1 + 4} = 3.
  4. cos⁡θ=49\cos\theta = \frac{4}{9}, so θ=cos⁡−149≈63.6∘\theta = \cos^{-1}\frac{4}{9} \approx 63.6^\circ.

What the sign tells you

Since lengths are positive, the sign of the dot product matches the sign of cos⁡θ\cos\theta. That gives a quick reading of the angle without computing it:

  • Positive: the angle is acute, less than 90 degrees, and the vectors point broadly the same way.
  • Zero: the vectors are perpendicular, also called orthogonal.
  • Negative: the angle is obtuse, more than 90 degrees, and the vectors point broadly in opposite directions.

The zero case is the most useful. For example, (3,4)⋅(4,−3)=12−12=0(3, 4) \cdot (4, -3) = 12 - 12 = 0, so these vectors are perpendicular. In two dimensions, swapping the components of a vector and negating one of them always produces a perpendicular vector, which is a handy trick for finding normals to lines.

Lengths and unit vectors

A vector dotted with itself gives its length squared, because the angle is zero and cos⁡0=1\cos 0 = 1:

a⋅a=∣a∣2\mathbf{a} \cdot \mathbf{a} = |\mathbf{a}|^2

So the length of (2,−1,3)(2, -1, 3) is 4+1+9=14≈3.742\sqrt{4 + 1 + 9} = \sqrt{14} \approx 3.742. Dividing a vector by its length produces a unit vector, which has length 1 and points in the same direction. Unit vectors are convenient because the dot product of two unit vectors is simply the cosine of the angle between them.

Projecting one vector onto another

The projection of a\mathbf{a} onto b\mathbf{b} is the shadow that a\mathbf{a} casts on the line through b\mathbf{b} when light shines perpendicular to that line. The dot product gives it directly:

proj⁡ba=a⋅b∣b∣2 b\operatorname{proj}_{\mathbf{b}}\mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|^2}\,\mathbf{b}

Example 3: a vector projection

  1. Project a=(4,2)\mathbf{a} = (4, 2) onto b=(3,1)\mathbf{b} = (3, 1).
  2. a⋅b=12+2=14\mathbf{a} \cdot \mathbf{b} = 12 + 2 = 14 and ∣b∣2=9+1=10|\mathbf{b}|^2 = 9 + 1 = 10.
  3. proj⁡ba=1410(3,1)=(4.2,1.4)\operatorname{proj}_{\mathbf{b}}\mathbf{a} = \frac{14}{10}(3, 1) = (4.2, 1.4).
  4. Check: the leftover part a−(4.2,1.4)=(−0.2,0.6)\mathbf{a} - (4.2, 1.4) = (-0.2, 0.6) should be perpendicular to b\mathbf{b}, and indeed 3(−0.2)+1(0.6)=03(-0.2) + 1(0.6) = 0.

The number a⋅b∣b∣\frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|}, about 4.427 here, is the scalar component of a\mathbf{a} along b\mathbf{b}: the signed length of the shadow. Projections split a vector into a part along a direction and a part perpendicular to it, a step used everywhere from physics to the least squares method in statistics.

Work done by a force

In physics, only the part of a force that acts along the direction of motion does work. The work done by a constant force F\mathbf{F} moving an object through a displacement d\mathbf{d} is therefore a dot product: W=F⋅d=∣F∣ ∣d∣cos⁡θW = \mathbf{F} \cdot \mathbf{d} = |\mathbf{F}|\,|\mathbf{d}|\cos\theta.

Example 4: pulling a sled

  1. A rope pulls a sled with a force of 50 newtons at 30 degrees above the horizontal, and the sled moves 10 metres along flat ground.
  2. W=50⋅10⋅cos⁡30∘=500⋅0.8660≈433W = 50 \cdot 10 \cdot \cos 30^\circ = 500 \cdot 0.8660 \approx 433 joules.
  3. The vertical part of the force does no work, because the sled does not move vertically.

Properties and applications

  • Commutative: a⋅b=b⋅a\mathbf{a} \cdot \mathbf{b} = \mathbf{b} \cdot \mathbf{a}.
  • Distributive: a⋅(b+c)=a⋅b+a⋅c\mathbf{a} \cdot (\mathbf{b} + \mathbf{c}) = \mathbf{a} \cdot \mathbf{b} + \mathbf{a} \cdot \mathbf{c}.
  • Scalars factor out: (ka)⋅b=k(a⋅b)(k\mathbf{a}) \cdot \mathbf{b} = k(\mathbf{a} \cdot \mathbf{b}).
  • Cauchy-Schwarz inequality: ∣a⋅b∣≤∣a∣ ∣b∣|\mathbf{a} \cdot \mathbf{b}| \le |\mathbf{a}|\,|\mathbf{b}|, which guarantees the cosine formula always gives a value between −1-1 and 1.

Beyond geometry, the dot product drives cosine similarity, which search engines and recommendation systems use to measure how alike two documents or users are; lighting in 3D graphics, where brightness depends on the dot product of the surface normal with the light direction; and neural networks, whose neurons compute dot products of inputs with weights. The dot product calculator computes the product, the angle and projections with steps, and the cross product calculator handles the other way of multiplying vectors, covered in our cross product guide.

A classic geometry problem

The dot product makes some geometry questions surprisingly quick. What angle does the long diagonal of a cube make with one of its edges? Place the cube with one corner at the origin and edges of length 1 along the axes. The diagonal runs from the origin to (1,1,1)(1, 1, 1), and one edge runs to (1,0,0)(1, 0, 0).

Their dot product is 1, the diagonal has length 3\sqrt{3} and the edge has length 1, so cos⁡θ=13\cos\theta = \frac{1}{\sqrt{3}} and θ≈54.7∘\theta \approx 54.7^\circ. Doing this with classical geometry requires constructing a right triangle inside the cube and reasoning carefully about its sides; with vectors it takes three lines. The same approach finds the angle between any two lines, planes or chemical bonds once you can describe their directions as vectors.

Common mistakes

  • Writing the answer as a vector, for example (8,0,−6)(8, 0, -6) instead of the sum 2.
  • Forgetting to take square roots when computing lengths for the angle formula.
  • Dividing by ∣b∣|\mathbf{b}| instead of ∣b∣2|\mathbf{b}|^2 in the vector projection formula.
  • Using degrees and radians inconsistently when evaluating cos⁡θ\cos\theta or its inverse on a calculator.
  • Concluding that vectors are perpendicular when one of them is actually the zero vector.

A good sanity check is the sign. If two vectors clearly point in similar directions in your sketch, the dot product must be positive; if your calculation gives a negative number, look for a sign error in one of the components.

Practice problems

Work these out, then compare with the answers that follow. First, find (1,3,−2)⋅(4,−1,5)(1, 3, -2) \cdot (4, -1, 5); the products are 4, −3-3 and −10-10, so the answer is −9-9, and the negative value means the angle is obtuse. Second, find kk so that (2,k)(2, k) is perpendicular to (3,−6)(3, -6): setting 6−6k=06 - 6k = 0 gives k=1k = 1. Third, find the angle between (1,0)(1, 0) and (1,1)(1, 1): the dot product is 1 and the lengths are 1 and 2\sqrt{2}, so the angle is 45 degrees, as a quick sketch confirms.

A short history

Vector notation is younger than most of school mathematics. In the 1840s, William Rowan Hamilton invented quaternions, numbers with one real and three imaginary parts, and the product of two of his pure quaternions contained both a scalar part and a vector part. In the 1880s, Josiah Willard Gibbs and Oliver Heaviside separated those two pieces into the dot product and the cross product, giving physicists the simpler vector algebra still taught today. Gibbs chose the centred dot as the symbol, which is how the operation got its everyday name.

Frequently asked questions

Is the dot product a vector or a number?

A number, which is why it is also called the scalar product. The cross product is the operation that produces a vector.

How do I know if two vectors are perpendicular?

Compute their dot product. If it is zero, and neither vector is the zero vector, they are perpendicular.

Can I take the dot product of vectors with different lengths?

Vectors of different magnitudes are fine, but they must have the same number of components. A two-component vector cannot be dotted with a three-component one.

Why does the dot product use the cosine of the angle?

Because ∣a∣cos⁡θ|\mathbf{a}|\cos\theta is the length of the part of a\mathbf{a} that lies along b\mathbf{b}. The dot product multiplies that aligned length by the length of b\mathbf{b}.

What does a dot product of zero mean for two nonzero vectors?

It means the vectors meet at a right angle. Neither has any component in the direction of the other, so the projection of one onto the other is the zero vector.

MathSolver Pro Editorial Team

Math content and review

Our editorial team writes every guide to explain the reasoning behind each method, not just the answer. Each worked example is checked against the site's own solver engines and automated tests before it is published, and articles are revised whenever a method or an exam format changes.