Dot Product Calculator
Find the dot product of two vectors in your browser. See the scalar result, each vector's magnitude, the cosine, and the angle between them — with the full element-wise working behind every number. No signup, nothing uploaded.
How it works
The dot product (also called the scalar product or inner product) takes two vectors of the same length and returns a single number. It is the sum of the products of matching components, and it underpins cosine similarity, projections, and most of the geometry used in machine learning. The definitions below follow Wolfram MathWorld and standard linear algebra.
For two equal-length vectors A = [a₁…aₙ] and B = [b₁…bₙ]:
A · B = Σ aᵢbᵢ = a₁b₁ + a₂b₂ + … + aₙbₙ
The tool computes the result and its geometry in four steps:
- Dot product. Multiply the vectors component by component and add the results:
A · B = Σ aᵢbᵢ. This single number is the scalar product. - Magnitudes.Take the square root of each vector's sum of squares:
‖A‖ = √(Σ aᵢ²)and likewise for‖B‖— the Euclidean magnitude, or L2 norm. - Cosine of the angle. Rearranging the geometric identity
A · B = ‖A‖‖B‖cosθgivescosθ = (A·B)/(‖A‖·‖B‖). This is defined only when both magnitudes are non-zero; a zero vector has no direction, so the tool shows a clear note instead of dividing by zero. - Angle. The angle is
θ = arccos(cosθ), shown in degrees and radians. The cosine is clamped to [−1, 1] first so floating-point drift never produces an invalid arccos.
The sign of the dot product alone tells you the kind of angle: positive means acute (the vectors broadly agree), zero means orthogonal (perpendicular, a right angle), and negative means obtuse, up to exactly opposite at 180°. As a credibility check, the calculator also recovers the dot product a second, independent way — the polarisation identity A·B = (‖A+B‖² − ‖A‖² − ‖B‖²)/2, which never multiplies aᵢ by bᵢ — and confirms the two routes agree.
Finding the angle between two vectors
Steps 2 to 4 above are, on their own, an angle between two vectors calculator: enter the pair and read θ straight off the result tile. The formula does not change with dimension, which is the part most people expect to be harder than it is. In 2-D, in 3-D, or across a 300-component embedding, the angle is always θ = arccos((A·B)/(‖A‖·‖B‖)), because the dot product and both magnitudes are sums over however many components the vectors happen to have.
Three cases, each built from the same three numbers:
- 2-D, acute. A = [3, 4], B = [4, 3]: A·B = 24, ‖A‖ = ‖B‖ = 5, so cosθ = 24/25 = 0.96 and θ = 16.26° (0.283794 rad).
- 2-D, obtuse. A = [1, 0], B = [−1, 1]: A·B = −1, ‖A‖ = 1, ‖B‖ = √2, so cosθ = −0.707107 and θ = 135° exactly. The negative dot product gives the obtuse answer away before you compute a single square root.
- 3-D. A = [2, 2, 1], B = [0, 3, 4]: A·B = 10, ‖A‖ = 3, ‖B‖ = 5, so cosθ = 10/15 = 0.666667 and θ = 48.19°. Same three steps, one more component.
Degrees and radians differ only by the factor 180/π, and this page prints both so the conversion is never a place to slip. If what you actually want is the straight-line distance between two points rather than the angle between two directions, use the Euclidean distance calculator instead — same input format, different question.
Properties that follow from the definition
- It is commutative.
A · B = B · A. Order never changes the answer, which is the opposite of the cross product, where swapping the two vectors flips the sign of the result. - It distributes over addition.
A · (B + C) = A · B + A · C. This is what lets a matrix–vector product be read as one dot product per row, and it is the reason a single artificial neuron is a dot product of weights and inputs before its activation runs. - It scales with either vector.
(kA) · B = k(A · B). Doubling one vector doubles the answer, so a raw dot product measures alignment and length, never alignment on its own. That is exactly why cosine similarity divides the dot product by both magnitudes before comparing anything. - A vector dotted with itself is its squared length.
A · A = ‖A‖², which is where step 2 above comes from: the magnitude is just the square root of that. - Cauchy–Schwarz bounds it.
|A · B| ≤ ‖A‖‖B‖guarantees the quotient in step 3 lands inside [−1, 1] in exact arithmetic, so arccos is always defined. Only binary floating point can push it a fraction of a billionth past the boundary — which is what the clamp absorbs.
Projection: what the number means geometrically
The dot product answers one concrete question: how much of A points along B? The scalar projection of A onto B is (A · B)/‖B‖, and the vector projection is ((A · B)/‖B‖²)·B. Take A = [4, 3] and B = [6, 0]. Then A · B = 4·6 + 3·0 = 24 and ‖B‖ = 6, so the scalar projection is 24/6 = 4 and the vector projection is (24/36)[6, 0] = [4, 0] — precisely the shadow A casts on the x-axis. The same formula is what a graphics engine evaluates for diffuse lighting (surface normal dotted with the light direction), and what a physics problem evaluates for work done by a force along a displacement.
Edge cases this calculator handles
- Zero vector. The dot product itself is still defined and equals 0, but a vector of length zero has no direction, so cosθ would divide by zero. The tool prints the dot product and suppresses the cosine and angle with a note rather than showing NaN.
- Mismatched lengths. A 2-component vector has no dot product with a 3-component one. The tool refuses and names both counts instead of padding with zeros or truncating, either of which would return a confident wrong answer.
- Very large components. Two vectors of 10⁹-sized components give a dot product near 10¹⁸, far below the double-precision ceiling of roughly 1.8×10³⁰⁸, so there is no overflow and no need for scaling tricks.
- Fractions, negatives, and scientific notation. Values like
-2.5or3e2parse normally; commas, spaces, tabs, newlines, and pasted square brackets are all accepted as separators. - High dimensions. Up to 10,000 components per vector are accepted — enough for a full embedding row. The step-by-step table stops after 100 rows for readability, but every component is included in the arithmetic.
- Rounding. Every intermediate value stays at full double precision until the final display. Rounding the magnitudes first is the single most common source of a wrong angle — see the worked examples and common mistakes below.
The dot product is the numerator of cosine similarity, so this page sits in the same family as the cosine similarity calculator and the Euclidean distance calculator, which measures straight-line separation rather than angle. All three run on the same parsed vectors, so you can paste the same pair into each.
Worked examples
Where the dot product is actually used
Outside a linear algebra exam, the dot product is doing quiet work in four places most people meet weekly.
Semantic search and recommendations. Text, images, and audio get turned into embedding vectors of a few hundred to a few thousand components. Ranking results means comparing a query vector against stored vectors, and the comparison is a dot product — either raw (when the vectors are already normalised, in which case the dot product is the cosine) or divided by both magnitudes as cosine similarity. If you are sizing a vector index rather than scoring one pair, the vector storage calculator works out what those embeddings cost to keep.
Neural networks. One artificial neuron computes a dot product of its weight vector with its input vector, adds a bias, then passes the scalar through an activation function such as the sigmoid or a softmax over the whole output layer. A matrix multiplication is nothing more than a grid of dot products, which is why GPU hardware is built around exactly this operation.
Statistics. Pearson correlation is the dot product of two mean-centred vectors divided by the product of their magnitudes — structurally identical to cosine similarity, applied to deviations from the mean rather than raw values. That relationship is worked through on the Pearson correlation calculator.
Physics and graphics. Work done by a constant force is W = F · d: only the component of force along the displacement counts, which is precisely what the dot product extracts. Diffuse lighting in a renderer is the surface normal dotted with the light direction, clamped at zero, so a face pointing away from the light contributes nothing.
The same operation also drives document similarity in classic search: weight the terms with TF-IDF, then score any two documents by the dot product of their weight vectors. Bag-of-words retrieval and modern embedding search differ in how the vectors are built, not in how they are compared.
Common mistakes
Five errors account for most wrong answers when the dot product is computed by hand.
- Confusing it with the element-wise product. [1, 2, 3] × [4, 5, 6] element by element is the vector [4, 10, 18]; the dot product is what you get after summing those, 32. NumPy uses
a * bfor the first anda @ bfor the second — a single character apart. - Rounding the magnitudes before dividing. With A = [1, 2, 3] and B = [4, 5, 6], rounding ‖A‖ to 3.74 and ‖B‖ to 8.77 gives cosθ = 0.975616 and θ = 12.68°, against a true 12.93°. A quarter of a degree lost to two harmless-looking roundings. Keep full precision until the last step.
- Reading a zero dot product as perpendicular without checking for a zero vector. The orthogonality test only holds when both vectors have non-zero length, as the edge-case example above shows.
- Mixing degrees and radians. Most programming languages, including JavaScript and Python, return arccos in radians. Multiply by 180/π to get degrees; this page shows both so the conversion is never a guess.
- Comparing raw dot products across different vector lengths. Because the dot product scales with magnitude, a longer vector scores higher without being any more similar. Normalise first, or compare cosines instead.
Frequently asked questions
Sources & references
- Wolfram MathWorld — Dot Product: A·B = Σ aᵢbᵢ, the identity A·B = ‖A‖‖B‖cosθ, and the orthogonality condition
- Wolfram MathWorld — L2-Norm: the Euclidean magnitude ‖a‖ = √(Σ aᵢ²) used for the magnitudes and angle
- NIST Digital Library of Mathematical Functions — standard reference for the inner product and vector norm
The formulas on this page were last cross-checked against these sources on 2026-08-29. The dot product is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.