Dot Product Calculator (2D, 3D and n-Dimensional)

Type two vectors as lists of numbers and this calculator multiplies matching components, adds them, and shows every term of that sum. It also returns both vector lengths, the cosine of the angle between them, the angle itself in degrees, the scalar projection of a onto b, and a plain verdict on whether the two are orthogonal. Any dimension works — two, three, four or more — because the definition never mentions how many components there are.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Vector aList the components separated by commas or spaces. Fractions such as 1/2 are accepted. Any number of components is allowed.3, -1, 2
Vector bMust have the same number of components as vector a, since only vectors from the same space can be dotted.1, 4, 5

It returns

  • Dot product a · b — Zero means the vectors are perpendicular.
  • Length |a|
  • Length |b|
  • Angle between a and b
  • cos θ — Always between −1 and +1, by the Cauchy-Schwarz inequality.
  • Scalar projection of a onto b — a·b / |b| — how far a reaches along the direction of b.

The formula

ab=i=1naibi=|a||b|cosθ
compba=ab|b|
|ab||a||b|

In plain text: a · b = Σ aᵢbᵢ = |a| |b| cos θ

  • a · bThe dot (scalar, inner) product — a single number, not a vector (product of the input units)
  • |a|The length of a, equal to √(a · a) (input units)
  • θThe angle between the two vectors, from 0° to 180° (degrees)
  • nThe number of components — the same for both vectors (—)

The algebraic sum and the geometric |a||b|cos θ are provably the same number; that equivalence is what makes the dot product useful.

Updated Category Vectors & Vector Operations Verified against published test cases Reading time 9 min

What the dot product measures

The dot product turns two vectors into one number, and that number measures alignment. Multiply matching components, add the results, and you have it: for (3, −1, 2) and (1, 4, 5) the sum is 3 − 4 + 10 = 9. There is no vector in the answer, which is why it is also called the scalar product.

The same number has a purely geometric description: |a||b| cos θ. Those two definitions look unrelated — one is bookkeeping over coordinates, the other is lengths and an angle — and the fact that they always agree is the central theorem about the operation. It is what lets you extract an angle from coordinates without ever drawing anything.

Read the sign first, because it carries most of the meaning. Positive means the angle is under 90° and the vectors broadly agree in direction. Zero means exactly 90°, perpendicular, with no component of one along the other. Negative means over 90° and broadly opposed. That three-way test is the reason the dot product appears in lighting models, in classifiers, in similarity search and in every projection formula you will meet.

Why the two formulas agree, and what follows from it

The bridge is the law of cosines. Take the triangle formed by a, b and ab. The law of cosines says |a − b|² = |a|² + |b|² − 2|a||b| cos θ. Expand the left side using the component definition and the cross terms collapse to −2(a · b). Comparing the two expressions gives a · b = |a||b| cos θ directly. No geometry is assumed beyond the law of cosines itself.

Three consequences do most of the work in practice.

Length from the product with itself. a · a = |a|² cos 0 = |a|², so |a| = √(a · a). Length is not a separate idea; it falls out of the dot product.

Angles without drawing. Rearranging gives cos θ = (a · b)/(|a||b|), which works in any number of dimensions. This is exactly the cosine similarity used to compare documents or embeddings, where the vectors have thousands of components and no picture is available.

Projection. The scalar projection of a onto b is (a · b)/|b|, the signed length of the shadow a casts along b's direction. Multiply by the unit vector along b and you get the vector projection, which is how any vector is split into a part along a given direction and a perpendicular remainder — the operation behind least squares, Fourier coefficients and Gram-Schmidt.

The Cauchy-Schwarz inequality |a · b| ≤ |a||b| is the guarantee that cos θ never leaves [−1, 1], and it holds with equality exactly when the vectors are parallel or antiparallel.

Worked example: a = (3, −1, 2) and b = (1, 4, 5)

  1. Multiply matching components. 3 × 1 = 3, then (−1) × 4 = −4, then 2 × 5 = 10.
  2. Add them. 3 − 4 + 10 = 9. That is the dot product. It is positive, so the angle is under 90°.
  3. Length of a. √(3² + (−1)² + 2²) = √(9 + 1 + 4) = √14 = 3.7416574.
  4. Length of b. √(1² + 4² + 5²) = √(1 + 16 + 25) = √42 = 6.4807407.
  5. Cosine. 9 / (3.7416574 × 6.4807407) = 9 / 24.2487113 = 0.3711537. Note that √14 × √42 = √588 = 24.2487113, so the product of the lengths can be taken in one square root.
  6. Angle. arccos(0.3711537) = 68.2132°.
  7. Scalar projection of a onto b. 9 / 6.4807407 = 1.3887301. So a reaches 1.39 units along the direction of b, against its own total length of 3.74 — most of a points somewhere else.

Sanity-check the cosine against Cauchy-Schwarz: 0.371 lies comfortably inside [−1, 1], as it must. And check the projection differently: the vector projection is 1.3887301 × (1, 4, 5)/6.4807407 = (0.2142857, 0.8571429, 1.0714286), whose length is 1.3887301 again ✓.

How to read the numbers

The sign is the headline. Positive, zero, negative maps onto acute, right, obtuse. In a lighting calculation, a negative dot product between a surface normal and the direction to the light means the surface faces away and receives nothing. In a classifier, the sign of w · x is the decision.

The cosine is the scale-free version. The raw dot product grows with both lengths, so it cannot be compared across different pairs. Dividing by |a||b| gives a number in [−1, 1] that depends only on direction, which is why cosine similarity rather than the raw product is what search and recommendation systems use.

The scalar projection has the units of a, not of a·b. Dividing by |b| cancels b's units, leaving a length along b's direction. It is negative when the angle exceeds 90°, meaning the shadow falls on the far side of the origin, and it is exactly |a| when the vectors are parallel.

Zero is a genuine verdict, not a failure. Orthogonality is the most useful special case in the subject: it is what makes a basis convenient, what makes a residual independent of the fit, and what makes the Pythagorean identity |a + b|² = |a|² + |b|² hold.

How the dot product varies with the angle

Two unit vectors at the stated angle. Multiply the last column by |a||b| for vectors of other lengths.
Angle θcos θRelationshipa · b for unit vectors
1Parallel, same direction1
30°0.866025Strongly aligned0.866025
45°0.707107Aligned0.707107
60°0.5Weakly aligned0.5
90°0Orthogonal0
120°−0.5Weakly opposed−0.5
135°−0.707107Opposed−0.707107
180°−1Antiparallel−1

For the worked example the cosine is 0.371154, which sits between the 60° and 90° rows — consistent with the computed angle of 68.2132°.

Mistakes worth avoiding

  • Expecting a vector back. The dot product is a single number. If you wanted a vector perpendicular to both inputs, that is the cross product.
  • Dotting vectors of different lengths. The sum Σ aᵢbᵢ has no meaning when the two lists differ in length; the operation is defined only within one vector space. The calculator refuses and says which counts failed to match.
  • Comparing raw dot products across pairs. A product of 100 between long vectors can mean less alignment than a product of 2 between short ones. Normalise to the cosine before comparing.
  • Reading a zero as an error. Zero is the orthogonality verdict, and it is the single most useful value the operation returns.
  • Assuming cancellation. a · b = a · c does not imply b = c. The two may differ by any vector perpendicular to a, which is a whole subspace of possibilities.
  • Forgetting the zero vector. It has a dot product of zero with everything and no direction of its own, so no angle exists. By convention it is counted as orthogonal to every vector, which keeps the theorems tidy.

Work is a dot product

The work done by a constant force is W = F · d, and the cos θ factor is the physics: only the component of the force along the displacement does any work. Push a trolley horizontally and all of your force counts; push down on it as you walk and none of that downward component does. Carry a suitcase along a level corridor and the work you do against gravity is exactly zero, because the vertical force and the horizontal displacement are orthogonal — a result that feels wrong to tired arms but is what the mathematics says.

The complementary operation is the cross product, which returns a vector perpendicular to both inputs and is largest exactly where the dot product is smallest. Together they pin down the geometry of a pair: the dot product supplies |a||b|cos θ and the cross product |a||b|sin θ.

If the angle is the whole point, the angle between vectors calculator gives it directly. If you want the projection as a vector rather than a length, together with the perpendicular remainder, use the vector projection calculator.

The dot product is also the atom of matrix arithmetic: entry (i, j) of a matrix product is the dot product of row i with column j, which the matrix multiplication calculator spells out term by term. In multivariable calculus, the directional derivative is the dot product of the gradient with a unit direction, so the rate of change along a direction is literally the alignment between that direction and the gradient found by the partial derivative calculator.

Frequently asked questions

What does a dot product of zero mean?

That the two vectors are orthogonal — they meet at exactly 90 degrees and neither has any component along the other. It is the standard perpendicularity test in any number of dimensions, and it works without computing an angle at all. A zero also occurs trivially whenever one of the vectors is the zero vector, which by convention counts as orthogonal to everything.

Can I take the dot product of vectors in 4 or more dimensions?

Yes, and the calculator handles any number of components. The definition Σ aᵢbᵢ never refers to the dimension, and every consequence carries over: lengths, the cosine formula and the Cauchy-Schwarz inequality all hold. High-dimensional dot products are the basis of cosine similarity between text embeddings, where the vectors have hundreds or thousands of components.

What is the difference between the dot product and the cross product?

The dot product returns a number and measures how much two vectors agree in direction; it is largest when they are parallel and zero when they are perpendicular. The cross product returns a vector perpendicular to both and measures how much area they span; it is largest when they are perpendicular and zero when they are parallel. The dot product works in any dimension, the cross product only in three.

How do I find the angle between two vectors?

Divide the dot product by the product of the lengths to get cos θ, then take the arccosine. For a = (3,−1,2) and b = (1,4,5) that is 9 / (√14 × √42) = 0.371154, giving 68.2132°. The result always lies between 0° and 180°, because that is the range of arccos and because an angle between two directions has no sense of sign.

Why is the dot product of a vector with itself the square of its length?

Because a vector makes an angle of zero with itself, so cos θ = 1 and the geometric formula gives |a||a| = |a|². Read from the component side, a · a = Σ aᵢ², which is the Pythagorean theorem in n dimensions. This is the standard way to compute a length: take the dot product with itself and square-root it.

Is the dot product commutative?

Yes: a · b = b · a always, because ordinary multiplication of the components commutes. It is also distributive over addition and compatible with scalar multiplication, which together make it a bilinear form. What it is not is associative, and the expression (a · b) · c is meaningless because a · b is a number and you cannot dot a number with a vector.

What is the scalar projection used for?

It gives the signed length of the shadow one vector casts along another, and it is the first step in splitting a vector into a component along a direction plus a perpendicular remainder. That split is behind least-squares fitting, Fourier coefficients, and the Gram-Schmidt process for building orthogonal bases. In physics it is how you extract the component of a force along a track or a slope.

What is a normal value for a dot product?

There is no normal value, because it scales with both lengths: doubling either vector doubles the product. The bounded quantity is the cosine, which always lies between −1 and +1 and depends only on direction. If you want to compare how well-aligned two different pairs of vectors are, compare cosines, not raw dot products.

References