Dot Product Calculator

The dot product measures how aligned two vectors are and returns one number. Enter two vectors of matching length, 2 to 8 components each, and this multiplies them out step by step, then gives the angle between them, their cosine similarity, and the projection of one onto the other. If you wanted the vector that points perpendicular to both, that is the cross product calculator instead.

Put this calculator on your website for free

Copy one snippet and give your visitors a working Dot Product Calculator.

Dot or cross: which one you want

Two vector products get taught side by side and confused ever after, so here is the split in one sentence each. The dot product answers "how aligned are these two vectors" and returns one number; it works in any dimension, and it is what this page computes. The cross product answers "what direction is perpendicular to both" and returns a whole vector, and it only exists in 3D. If the perpendicular direction is what you came for, the cross product calculator is the page you want.

How the dot product works

Line the two vectors up, multiply matching components, and add the products. That is the entire recipe, and it compresses everything about how two vectors relate directionally into a single number: large and positive when they pull the same way, zero when they are perpendicular, negative when they oppose each other.

The reason one humble sum can say all that is the second identity below: the dot product equals the product of the two lengths times the cosine of the angle between them. Divide the two lengths away and you are left holding the cosine itself, which is where the angle and the cosine similarity on this page both come from.

The formula

a · b = a1b1 + a2b2 + a3b3, one product per matching pair, however many components the vectors have
a · b = |a| × |b| × cos θ

Here a1 and b1 are the first components of each vector, |a| and |b| are the magnitudes (the straight-line lengths, from the square root of each vector dotted with itself), and θ is the angle between the two vectors. The first line is how you compute it; the second is what it means.

Worked example

a = (2, 3) and b = (4, 1).

a · b = (2)(4) + (3)(1) = 8 + 3 = 11

|a| = √(4 + 9) = √13 = 3.605551
|b| = √(16 + 1) = √17 = 4.123106

cos θ = 11 ÷ (3.605551 × 4.123106) = 0.739940, so θ = 42.27 degrees (0.7378 radians).

That 0.739940 is also the cosine similarity of the two vectors: fairly aligned, well short of parallel.

The scaling trap

Here is the mistake that bites everyone who dots raw data instead of geometry homework. Take two houses as vectors of price in dollars, size in square meters, and bedrooms: a = (300000, 150, 3) and b = (450000, 200, 4).

The raw dot product is 135,000,030,012. Of that, the price term alone is 135,000,000,000. The size term added 30,000, and the bedrooms contributed twelve. Whatever this number measures, it is not the similarity of two houses; it is the price column talking to itself with two other columns whispering underneath.

Nothing went wrong with the arithmetic. The trap is units: dollars run five orders of magnitude larger than bedrooms, so the biggest-unit feature silently becomes the whole answer. The fix is to normalize before you compare, either by scaling each feature to a common range or by using cosine similarity, which divides the magnitudes away. Run these two houses through this page and the cosine similarity comes back as 1.0000 to four decimals, an angle of about 0.003 degrees, which is the same lesson from the other side: once direction is all that counts, two houses whose numbers are each about 1.5 times the other's point almost exactly the same way.

Cosine similarity: one number, two names

Divide the dot product by both magnitudes and you get the cosine of the angle between the vectors. A geometry classroom calls that the cosine of θ. A machine learning course calls it cosine similarity and uses it to compare embeddings, the long vectors a model assigns to words, sentences and images. It is the same number wearing two name tags, and this page prints it under both.

Cosine similarityReading
1Same direction exactly
0.7 to 1Strongly aligned
Near 0Roughly unrelated directions
-0.7 to -1Strongly opposed
-1Opposite direction exactly

One honest caveat about that table: the endpoints are mathematics, but the bands between them are conventions, not universal rules. What counts as "similar enough" depends entirely on the data. Text embeddings from some models rarely dip below 0.5 for any pair of sentences, so a 0.7 there means much less than a 0.7 between hand-built feature vectors. Calibrate against your own data before trusting a cutoff.

Zero means perpendicular

When the dot product of two nonzero vectors is exactly zero, the vectors are perpendicular: the cosine of 90 degrees is zero and nothing else in the formula can rescue it. The converse is the practical tool: to test whether two directions are at right angles, dot them and look for zero. No protractor, no trigonometry, just multiply and add. This page uses that same test on itself, showing that the leftover after a projection is perpendicular to the vector you projected onto.

Three norms, three ways to measure a vector

The magnitude used above is the L2 norm, but it has two siblings worth knowing, and this page reports all three for each vector you enter.

In machine learning these are working tools, one plain job each: L1 and L2 measure error (mean absolute error against mean squared error) and drive the two classic regularizations, where an L1 penalty pushes small weights all the way to zero and an L2 penalty shrinks everything a little. L-infinity bounds the worst single case, which is what you care about when one bad component is one too many.

Where the dot product does physical work

The word "work" in physics is a dot product wearing overalls: work equals force times distance times the cosine of the angle between them, which is exactly force dotted with displacement. Pull a sled with a rope angled 60 degrees above the ground and only half your force (cos 60 = 0.5) moves the sled forward; the rest tugs it upward and does no work along the ground. The projection this page computes is that decomposition made explicit. For the force side of that calculation, the force calculator is next door.

Frequently asked questions

Is cosine similarity the same as the dot product?

Nearly. Cosine similarity is the dot product divided by both magnitudes, which makes it exactly the cosine of the angle between the two vectors. The raw dot product mixes alignment with size; cosine similarity keeps only the alignment, which is why machine learning uses it to compare embeddings that come in different lengths.

How do you calculate the magnitude of a vector?

Square every component, add the squares, and take the square root: the magnitude of (3, 4) is the square root of 9 + 16, which is 5. It is the Pythagorean theorem doing its job in any number of dimensions, and it is the L2 norm this page computes for both of your vectors.

Can a dot product be negative?

Yes. A negative dot product means the angle between the vectors is past 90 degrees, so they point in broadly opposite directions. At exactly 180 degrees the dot product reaches its most negative possible value, minus one times the product of the two magnitudes.

What is the dot product of perpendicular vectors?

Exactly zero, every time, because the cosine of 90 degrees is zero. The converse is just as useful: if two nonzero vectors have a dot product of zero, they are perpendicular. That test is how orthogonality is checked in practice, from geometry homework to signal processing.

What is a unit vector for?

A unit vector is a direction with the length divided away: it has magnitude exactly 1 but keeps the original direction. That lets you compare directions fairly, build coordinate frames, and scale a direction to any length you want by simple multiplication.

Why normalize vectors before comparing them?

Because raw components carry units, and the biggest unit quietly takes over. Dot two rows of house data and the price column, being in the hundreds of thousands, contributes essentially the whole answer while the bedroom count contributes a rounding error. Scaling features to a common range, or comparing by cosine similarity, divides that distortion away.

What does the projection of one vector onto another mean?

It is the shadow one vector casts along the other: the part of a that points along b, with the perpendicular part removed. In physics it is how much of a force actually acts along a direction of motion, which is why work is force times distance times the cosine of the angle.

Do I want the dot product or the cross product?

Ask what shape of answer you want. If you want one number saying how aligned two vectors are, that is the dot product, and it works in any dimension. If you want a third vector at right angles to both, that is the cross product, and it only exists in 3D.

Related calculators