Vector Magnitude Calculator

Vector Magnitude Calculator |v|

Enter one vector as comma or space separated numbers (2D like 3 4 or 3D like 1 2 2). You get the magnitude (length), the unit vector, the sum of squares, and the dimension — plus a live 2D diagram showing the Pythagorean legs, the steps, and the NumPy code.

Examples:

This free vector magnitude calculator takes a single vector — in 2D or 3D — and instantly returns its magnitude (length), the unit vector that points the same way, the sum of squared components, and the dimension. For 2D inputs it also draws the vector on a plane along with the two dashed legs that make the Pythagorean triangle visible, then shows every step and the matching NumPy code. Type your components above, press Compute, and you see exactly how the length is built rather than just a lone number.

What vector magnitude means

The magnitude of a vector is its length — the straight-line distance from the origin to the point the vector reaches. It is also called the vector's norm or, more precisely, its L2 norm or Euclidean norm. A vector like [3, 4] starts at the origin and ends at the coordinate (3, 4); its magnitude is how far that endpoint sits from the start, which turns out to be exactly 5. In three dimensions a vector such as [1, 2, 2] reaches into space, and its magnitude 3 measures that same origin-to-tip distance. The magnitude is always a single non-negative number: direction is thrown away, and only size remains.

Written with symbols, the magnitude of a vector v with components v1, v2, ..., vn is the square root of the sum of the squares of those components. Because it collapses an ordered list of numbers into one scalar, the magnitude is the natural way to answer the question "how big is this vector?" — whether the vector is a physical displacement, a velocity, a gradient in an optimizer, or a row of features in a dataset.

Everything on this page is computed in your browser from the numbers you type. Nothing is uploaded, and the diagram, steps, and NumPy snippet refresh the instant you change a value or the decimal setting.

How to use the vector magnitude calculator

  1. Type Vector v as comma or space separated numbers. Use two components for a 2D vector (3 4) or three for a 3D vector (1 2 2).
  2. Press Compute. The stat tiles fill in with the magnitude (highlighted), the unit vector, the sum of squares, and the dimension.
  3. For 2D inputs, read the plane diagram: the indigo arrow is your vector, and the two grey dashed legs are its horizontal and vertical components — the sides of the right triangle whose hypotenuse is the magnitude.
  4. Use the Decimals selector to switch between automatic precision and a fixed 0, 2, or 4 places, and press Copy result to grab a one-line summary.
  5. The example chips are the quickest way to explore: 2D loads the classic 3-4-5 triangle, 3D gives a clean length-3 vector, Unit shows a vector that already has magnitude 1, and Random throws a fresh 2D vector at the plane.

A worked example

Take v = [3, 4]. Square each component: 3² = 9 and 4² = 16. Add them: 9 + 16 = 25. The magnitude is the square root of that sum, √25 = 5. This is the famous 3-4-5 right triangle: the horizontal leg has length 3, the vertical leg has length 4, and the hypotenuse — the vector itself — has length 5. The diagram draws exactly this, with the two dashed legs meeting at a right angle beneath the indigo arrow.

Now try a 3D case, v = [1, 2, 2]. The squares are 1, 4, 4, their sum is 9, and the magnitude is √9 = 3. The three-dimensional formula is the same idea extended by one more term: you still square every component, add, and take the square root. That is why the magnitude generalises the Pythagorean theorem to any number of dimensions without changing shape.

The formula

For a vector v = [v1, v2, ..., vn], the magnitude is

|v| = √(v1² + v2² + ... + vn²) = √(Σ vi²)

In two dimensions this reads |v| = √(v1² + v2²), and in three dimensions |v| = √(v1² + v2² + v3²). The intermediate quantity inside the root — the sum of squares — is worth naming on its own, because it appears throughout statistics and machine learning as the squared L2 norm, and because squaring keeps every term positive so cancellation can never occur. The magnitude is always zero or larger, and it equals zero only for the zero vector, all of whose components are zero.

Unit vectors and normalization

A unit vector is a vector whose magnitude is exactly 1. Any non-zero vector can be turned into a unit vector pointing the same direction by dividing each component by the magnitude: u = v / |v|. This process is called normalizing the vector, and the result is sometimes written v-hat. For v = [3, 4] the unit vector is [3/5, 4/5] = [0.6, 0.8], which is why the Unit example loads 0.6 0.8 — a vector that is already normalized and returns magnitude 1. Normalization strips away size and keeps only direction, which is exactly what you want when you care where a vector points but not how long it is.

The one vector you cannot normalize is the zero vector. It has no direction, so dividing by its magnitude means dividing by zero. This calculator detects that case and reports that the zero vector has no direction and its magnitude is 0, rather than returning nonsense.

Vector magnitude in Python with NumPy

In real work you will compute magnitudes in code, and NumPy makes it a one-liner:

import numpy as np
v = np.array([3, 4])
print(np.linalg.norm(v)) # magnitude -> 5.0
print(np.sqrt(np.sum(v**2))) # same thing, spelled out
unit = v / np.linalg.norm(v)
print(unit) # [0.6 0.8]
# 3D works identically:
print(np.linalg.norm([1, 2, 2])) # -> 3.0

The function numpy.linalg.norm returns the L2 norm by default, which is precisely the magnitude this page computes. You can prototype a value here and reproduce it in code with confidence, because both use the same definition: square, sum, and take the root. Passing ord=1 to numpy.linalg.norm would instead give the L1 norm (the sum of absolute values), a different measure of size that is useful in its own contexts but is not what "magnitude" usually means.

Where vector magnitude shows up in machine learning

Magnitude is one of the most heavily used quantities in machine learning, and it wears several hats. As the L2 norm, it measures the size of a weight vector in ridge regression and in the weight-decay term of neural-network training, where penalising large magnitudes keeps a model from overfitting. During feature normalization, dividing each sample vector by its magnitude puts every example on the unit sphere, so that comparisons depend on direction rather than raw scale — the backbone of cosine similarity in search and recommendation systems. Magnitude is also the foundation of Euclidean distance: the distance between two points is just the magnitude of the vector connecting them, which is what k-nearest-neighbours and k-means clustering compute millions of times. And in optimization, the magnitude of the gradient vector tells you how steep the loss surface is; gradient clipping rescales a gradient whenever its magnitude exceeds a threshold, which stabilises the training of deep and recurrent networks. Understanding magnitude by hand makes all of these techniques far less mysterious when you meet them in papers and frameworks.

Common mistake
Do not confuse the sum of squares with the magnitude — you still have to take the square root at the end, so the magnitude of [3, 4] is 5, not 25. Another frequent slip is trying to normalize the zero vector: dividing by a magnitude of zero is undefined, because a zero vector has no direction. Finally, remember that magnitude discards sign and direction entirely: [3, 4] and [-3, -4] have the same magnitude of 5, even though they point opposite ways.

Frequently asked questions

What is the magnitude of a vector?

The magnitude is the length of the vector — the straight-line distance from the origin to its tip. You compute it by squaring every component, adding those squares, and taking the square root of the total. It is always a single non-negative number.

Is vector magnitude the same as the norm?

Yes, the magnitude is the L2 norm (also called the Euclidean norm) of the vector. Other norms exist — the L1 norm sums absolute values, for example — but when people say "magnitude" or "length" they almost always mean the L2 norm this calculator returns.

How do I turn a vector into a unit vector?

Divide each component of the vector by its magnitude. The result has length 1 and points in the same direction. This is called normalizing the vector, and the calculator shows the unit vector alongside the magnitude.

Can the magnitude be negative?

No. Because every component is squared before summing, the value inside the square root is never negative, so the magnitude is always zero or positive. It equals zero only for the zero vector.

Does this calculator work for 3D vectors?

Yes. Enter three components, such as 1 2 2, and the tool returns the magnitude, unit vector, sum of squares, and dimension. The plane diagram is drawn only for 2D vectors, but every numeric result works in 3D.

Related calculators

Explore the full linear algebra calculators hub, work with two vectors at once in the vector calculator, or project one vector onto another with the vector projection calculator.