Cosine Similarity Calculator - Vector Score and Angle

Use this cosine similarity calculator to compare two vectors. Pick a dimension, enter the components, and get the dot product, similarity score, and angle.

Updated: June 16, 2026 • Free Tool

Cosine Similarity Calculator

Number of components in each vector. Choose 2, 3, 4, or 5. Only the first n components of A and B are used.

First component of vector A.

Second component of vector A.

Third component of vector A. Only used when n >= 3.

Fourth component of vector A. Only used when n = 4 or 5.

Fifth component of vector A. Only used when n = 5.

First component of vector B.

Second component of vector B.

Third component of vector B. Only used when n >= 3.

Fourth component of vector B. Only used when n = 4 or 5.

Fifth component of vector B. Only used when n = 5.

Results

Cosine similarity cos(θ)
0
Angle (degrees) 0°
Angle (radians) 0rad
Dot product A·B 0
Magnitude of A (||A||) 0
Magnitude of B (||B||) 0

What Is a Cosine Similarity Calculator?

A cosine similarity calculator measures how close two vectors point in the same direction. It returns a unitless score in [-1, 1] that equals 1 for parallel, 0 for orthogonal, and -1 for opposite vectors, plus the dot product, the magnitudes, and the angle in degrees and radians.

  • Information retrieval and document similarity: Score two text documents represented as bag-of-words or TF-IDF vectors to see whether they cover the same topic, without caring about document length.
  • Recommendation systems and embedding search: Compare a query embedding against a catalog of item embeddings to find the closest matches, since cosine similarity is the standard measure for dense vector search.
  • Linear algebra homework and sanity checks: Verify a hand-computed dot product, magnitudes, or angle for a textbook problem, including cases that come out to clean values like 0, 1, -1, or a 90-degree angle.

Cosine similarity ignores magnitude, so two vectors that point the same direction always score 1 even when one is much longer than the other, which is exactly why it is the standard for length-normalized text vectors.

The numerator of the formula is just the dot product, so when you only need that piece of the answer, the Dot Product Calculator page runs the same component multiplication and addition on a fresh pair of inputs.

How the Cosine Similarity Calculator Works

The page implements the cosine similarity formula: the dot product of the two vectors divided by the product of their Euclidean magnitudes. It reads the first n components, computes the dot product, the two norms, and the angle, and clamps the final score to [-1, 1].

cos(θ) = (A · B) / (||A|| · ||B||) = Σ(aᵢ · bᵢ) / ( sqrt(Σ aᵢ²) · sqrt(Σ bᵢ²) )
  • A and B: The two input vectors, each with n real components.
  • A . B: Dot product: sum of a_i * b_i. The numerator of the formula.
  • ||A|| and ||B||: Euclidean magnitudes of A and B. Together they form the denominator.
  • cos(theta): The cosine similarity, in [-1, 1]: 1 for parallel, 0 for orthogonal, -1 for opposite vectors.

The same formula works for any positive integer n, so the calculator accepts 2D through 5D inputs. The magnitudes in the denominator handle the normalization for you.

Worked example: a 45-degree angle in 2D

Vector A = (1, 1). Vector B = (1, 0). n = 2.

A . B = (1)(1) + (1)(0) = 1. ||A|| = sqrt(1 + 1) = sqrt(2). ||B|| = 1. cos(theta) = 1 / sqrt(2).

cos(theta) = 0.7071, theta = 45.00 degrees (0.7854 rad).

The two vectors differ but lean in similar directions, so the score sits between 0 and 1, and the 45-degree angle matches the diagonal of a unit square.

According to Wikipedia (Cosine similarity), the cosine similarity between two n-dimensional vectors A and B is defined as the dot product A·B divided by the product of their Euclidean norms, which equals the cosine of the angle between them.

The two magnitudes in the denominator come from the same arithmetic as a single-vector L2 norm, which the Vector Magnitude Calculator page computes directly when you only need the length of one vector.

Key Concepts Behind Cosine Similarity

Four short ideas explain why the formula looks the way it does and how to read the score you get back.

Dot product A . B

The dot product is the sum of a_i * b_i over the first n components. It is the numerator of the formula, and it is positive when the vectors lean the same way, negative when they lean opposite ways, and 0 when they are orthogonal.

Euclidean magnitude (L2 norm)

The magnitude is the square root of the sum of the squared components. The two magnitudes form the denominator and normalize the dot product by the lengths of A and B, so the score is independent of the original vector lengths.

The cosine of the angle

A . B equals ||A|| * ||B|| * cos(theta) by definition, so dividing both sides by ||A|| * ||B|| leaves cos(theta). A score of 1 means theta = 0 degrees, 0 means theta = 90 degrees, and -1 means theta = 180 degrees.

Why 'similarity' instead of 'distance'

Cosine similarity is a similarity measure, so larger values mean more similar. The corresponding distance is 1 - similarity. Many vector search systems use cosine distance, but the underlying geometry is the same.

Once you know the dot product, the two magnitudes, and the angle, the cosine similarity follows from one division, and the rest of the page is just rounding and unit conversion.

If your data has a meaningful mean and you want to measure whether two series move together rather than whether two weight vectors point the same way, the Pearson Correlation Calculator page is the centred-data version of this same idea.

How to Use This Cosine Similarity Calculator

Five short steps cover everything from a clean 2D textbook example to a 5D embedding-like input.

  1. 1 Pick a dimension: Choose 2, 3, 4, or 5. Only the first n components of each vector are used, so higher components can stay at 0 unless you actually need them.
  2. 2 Enter the components of vector A: Type a1, a2, ... in order. Negative numbers, decimal numbers, and large numbers are all allowed.
  3. 3 Enter the components of vector B: Type b1, b2, ... in the matching order. Components past n are ignored.
  4. 4 Read the primary result: The cosine similarity appears in the large primary tile. The closer it is to 1, the more the two vectors point the same way; the closer to -1, the more they point opposite ways; 0 means orthogonal.
  5. 5 Use the supporting values: Read the angle in degrees or radians to translate the score into a geometric angle, and inspect the dot product and magnitudes.

Try the 3D example A = (1, 2, 1) and B = (2, 1, 1). The calculator returns dot product = 5, ||A|| = ||B|| = sqrt(6) ~ 2.4495, similarity = 5/6 ~ 0.8333, and angle ~ 33.56 degrees (0.5857 rad). That is the kind of high-but-not-1 score that is typical for two related but not identical document embeddings.

When the two vectors are best read as point coordinates and you care about the actual distance between them instead of the angle, the 2D Distance Calculator page turns the same (x, y) pairs into a Euclidean distance with the step-by-step math.

Benefits of Using This Cosine Similarity Calculator

These benefits matter most when you need a quick, transparent similarity score and do not want to re-derive the formula or write a script.

  • Transparent step-by-step math: The page shows the dot product, both magnitudes, the angle, and the similarity in one view, so you can see which arithmetic produced the score.
  • Works for 2D through 5D: Choose 2, 3, 4, or 5 components without reloading. The same formula runs on the first n components, matching how cosine similarity is used in text retrieval and embedding search.
  • Returns the angle in two units: Read the angle in degrees or radians. Degrees are 0 to 180, radians are 0 to pi.
  • Handles negative and decimal components: Negative weights, decimal weights, and large weights all use the same formula. The page does not require you to normalize the inputs first.
  • Catches the zero-vector edge case: If either vector is all zeros, the page shows a clear error explaining that cosine similarity is undefined when there is no direction to compare.

Use the page to confirm a homework answer, sanity-check an embedding search, or pre-validate a pair of vectors before you hand them to a longer script.

If you already have a cosine similarity score and only need the angle in degrees or radians, the cos⁻¹ (arccos) Calculator page runs arccos on a single number without re-typing the vectors.

Factors That Affect the Cosine Similarity Result

The formula is the same in every case, but a few factors change how the score should be read and what it tells you about the inputs.

Vector magnitude

Magnitude does not appear in the final score, because the two norms cancel. Two vectors that point the same direction always score 1, even when one is ten times longer than the other.

Number of components (dimension)

The result only uses the first n components. Higher-dimensional inputs use the same formula, but the score averages over more terms, which can dilute the influence of any single component.

Zero vectors

If either vector is the zero vector, the magnitude is 0 and the formula divides by zero. The page returns a clear error, because there is no direction to compare when a vector has no length.

Sign of the components

Negative components are allowed and they affect the dot product directly. A mostly-positive vector can still score close to -1 against an opposing vector, and mixed-sign vectors often land near 0.

  • Cosine similarity ignores magnitude, so two vectors with very different lengths but the same direction will always score 1. When magnitude matters, use the 2D or 3D distance calculator on the underlying coordinates.
  • The formula returns a value in [-1, 1], not a probability. A score of 0.5 is not a 50% chance that two documents are duplicates; it just means the angle between the vectors is 60 degrees.
  • The result is meaningful only when both vectors are non-zero. The page blocks the calculation for zero vectors, but the underlying geometry still leaves the comparison undefined in that case.

According to scikit-learn, cosine_similarity computes the cosine of the angle between two vectors, returned as a similarity score in the range [-1, 1] that equals 1 for parallel vectors and -1 for opposite vectors, with the corresponding cosine distance defined as 1 minus this score.

When magnitude does matter for the same two 3D inputs and you want the actual length of the line between them rather than the angle, the 3D Distance Calculator page handles the (x, y, z) case directly.

cosine similarity calculator showing two vectors with their dot product, magnitudes, similarity score, and angle in degrees and radians
cosine similarity calculator showing two vectors with their dot product, magnitudes, similarity score, and angle in degrees and radians

Frequently Asked Questions

Q: What is the cosine similarity formula?

A: The cosine similarity formula is cos(θ) = (A · B) / (||A|| · ||B||). Take the dot product of the two vectors, divide it by the product of their Euclidean magnitudes, and the result is the cosine of the angle between them.

Q: How do you calculate cosine similarity between two vectors?

A: Multiply matching components of A and B and add the products to get the dot product. Square each component of A and add them, then take the square root to get ||A||. Repeat for B to get ||B||. Divide the dot product by ||A|| · ||B|| and the result is the cosine similarity in [-1, 1].

Q: What does a cosine similarity of 1, 0, or -1 mean?

A: A cosine similarity of 1 means the two vectors are parallel and point in the same direction. A score of 0 means the vectors are orthogonal, so there is no shared direction. A score of -1 means the vectors are anti-parallel, pointing in exactly opposite directions.

Q: Can cosine similarity be negative?

A: Yes. Cosine similarity is the cosine of an angle, and the cosine is negative for angles between 90° and 180°. A negative score means the two vectors point in opposite directions, with -1 being the most opposite case.

Q: How is cosine similarity different from Euclidean distance?

A: Cosine similarity measures direction only, so two vectors that point the same way always score 1 regardless of length. Euclidean distance measures straight-line length between two points, so it grows with magnitude. Use cosine similarity for text and embeddings, and Euclidean distance for physical position.

Q: What is a good cosine similarity threshold?

A: There is no universal threshold, but in practice scores above 0.9 are usually treated as near-duplicates, scores from 0.7 to 0.9 are clearly related, scores around 0.5 are weakly related, and scores below 0.2 are essentially unrelated. The right value depends on the data and the cost of a false positive in your workflow.