Dot Product Calculator

Dot Product Calculator a · b

Enter two vectors of the same length (numbers separated by spaces or commas). The calculator returns the dot product, both magnitudes, and the angle between the vectors.

Examples:

This free dot product calculator multiplies two vectors of the same length and instantly returns their dot product, the magnitude of each vector, and the angle between them. Type vector a and vector b above, press Calculate, and you get the scalar result a · b together with the geometry that makes the dot product one of the most useful operations in all of linear algebra — no sign-up, works on mobile.

What is the dot product?

The dot product (also called the scalar product or inner product) takes two vectors of equal length and combines them into a single number. You multiply the vectors component by component and add the results. For two three-dimensional vectors a = [a1, a2, a3] and b = [b1, b2, b3], the dot product is a1·b1 + a2·b2 + a3·b3. The answer is always a single scalar, never another vector — which is exactly why it is called the scalar product.

Two conditions must hold for the dot product to exist. First, both vectors must have the same number of components: you cannot dot a 2-dimensional vector with a 3-dimensional one. Second, the vectors are treated as ordered lists, so the pairing is positional — the first component of a multiplies the first component of b, and so on. The calculator above enforces the length rule for you and explains the problem clearly if the two vectors do not match.

The rule in one line

The dot product is the sum of the pairwise products of matching components: a · b = a1·b1 + a2·b2 + … + an·bn. The result is a single number that encodes both length and direction information about the two vectors.

How to use the dot product calculator

The tool is intentionally simple. Each vector is entered as a short list of numbers on a single line:

  1. Enter Vector a — for example 1 2 3. You may separate the numbers with spaces or commas; both work.
  2. Enter Vector b with the same number of components as a — for example 4 5 6.
  3. Press Calculate. The dot product appears highlighted, alongside the magnitude of each vector and the angle between them in degrees.
  4. Press Clear to empty both fields and start again.

If the two vectors have different lengths, the calculator refuses to guess. Instead it tells you exactly how many components each vector has, so you can correct the input rather than trust a silently wrong answer. If either vector is the zero vector, the angle is reported as undefined because a vector with no length has no direction.

Step-by-step worked example

Suppose a = [1, 2, 3] and b = [4, 5, 6]. Both have three components, so the dot product is defined. Multiply matching entries and add:

a · b = (1)(4) + (2)(5) + (3)(6) = 4 + 10 + 18 = 32.

To find the angle, you also need the magnitudes. The magnitude of a vector is the square root of the sum of its squared components:

|a| = sqrt(1² + 2² + 3²) = sqrt(14) ≈ 3.741657 and |b| = sqrt(4² + 5² + 6²) = sqrt(77) ≈ 8.774964.

Now apply the geometric formula, cos(theta) = (a · b) / (|a| · |b|) = 32 / (3.741657 × 8.774964) ≈ 0.974632. Taking the inverse cosine gives theta ≈ 12.933°. The two vectors point in almost the same direction, which fits the intuition: their components grow in the same pattern. The calculator above reproduces every one of these numbers.

The geometric meaning: a · b = |a||b|cos(theta)

The algebraic sum-of-products definition has a beautiful geometric twin. For any two vectors, the dot product also equals the product of their magnitudes times the cosine of the angle between them:

a · b = |a| · |b| · cos(theta).

Rearranged, this lets you recover the angle from the components alone: cos(theta) = (a · b) / (|a| |b|). Because the cosine controls everything, the sign of the dot product is a compact directional signal:

  • A positive dot product means the angle is less than 90° — the vectors point in broadly the same direction.
  • A dot product of zero means the vectors are exactly perpendicular (orthogonal), since cos(90°) = 0.
  • A negative dot product means the angle is greater than 90° — the vectors point in broadly opposite directions.

This is why the dot product is the workhorse for measuring similarity: without ever drawing a picture, its sign and size tell you how aligned two vectors are. When the magnitudes are held constant, a larger dot product simply means a smaller angle and tighter alignment.

Dot product in Python with NumPy

You will rarely compute large dot products by hand. In Python, NumPy makes it a single call with numpy.dot:

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
d = np.dot(a, b) # 32
mag_a = np.linalg.norm(a) # 3.7416573...
mag_b = np.linalg.norm(b) # 8.7749643...
cos_t = d / (mag_a * mag_b)
angle = np.degrees(np.arccos(np.clip(cos_t, -1, 1)))
print(d, angle) # 32 12.9331...

Two details are worth noting. The np.clip(cos_t, -1, 1) guard protects against tiny floating-point errors that can push the cosine a hair above 1 or below -1, which would make arccos return nan. The calculator above performs the same clamp. Also note that for the flat 1-D arrays shown here, np.dot returns the scalar dot product; the @ operator does the same thing for vectors, though it means full matrix multiplication when the operands are 2-D.

Common mistakes to avoid
The three errors that trip up most learners are: dotting two vectors of different lengths (the operation is undefined — the calculator will stop you); confusing the dot product with the cross product, which returns a vector and only exists in three dimensions; and forgetting to clamp the cosine before calling arccos, which produces nan from rounding error. When you get a scalar back, it is a dot product; when you get a vector back, it is a cross product.

Where the dot product powers machine learning

The dot product is arguably the single most executed operation in modern machine learning. Every artificial neuron computes a weighted sum of its inputs — that weighted sum is exactly the dot product of the input vector with the neuron’s weight vector, before a bias is added and an activation is applied. A layer of neurons stacks these dot products into a matrix multiplication, so the entire forward pass of a neural network is dot products at scale.

Cosine similarity, the standard way to measure how related two embeddings are, is built directly on the formula above: it is the dot product of two vectors divided by the product of their magnitudes, which isolates cos(theta). Search engines, recommendation systems, and retrieval-augmented generation all rank items by cosine similarity between embedding vectors. In the transformer architecture behind large language models, attention scores are dot products too: each query vector is dotted with every key vector to decide how much focus one token should place on another. Understanding this one operation demystifies a huge slice of applied machine learning.

Frequently asked questions

What do the two vectors need to have in common?

They must have the same number of components. You can dot a 3-component vector only with another 3-component vector. If the lengths differ, the dot product is undefined, and the calculator will tell you the length of each vector.

What does the sign of the dot product mean?

A positive result means the angle between the vectors is less than 90° (similar direction), zero means they are perpendicular, and a negative result means the angle is greater than 90° (opposing directions).

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

The dot product returns a single scalar and works in any dimension. The cross product returns a new vector perpendicular to both inputs and is defined only in three dimensions. They answer different questions.

Why is the angle sometimes undefined?

The angle comes from cos(theta) = (a · b) / (|a| |b|). If either vector is the zero vector its magnitude is 0, the division is impossible, and a zero-length vector has no direction — so the angle is reported as undefined.

Can the dot product be negative or zero?

Yes. A negative dot product signals vectors pointing more than 90° apart, and exactly zero means the vectors are orthogonal. Only the magnitudes are always non-negative.

Related calculators

Explore the full linear algebra calculators hub, or jump to the cross product calculator and the matrix multiplication calculator to keep building your toolkit.