In n dimensions, the length of a vector v = (v1, v2, …, vn) is ‖v‖ = √v12 + v22 + ⋯ + vn2, called the Euclidean norm. It is the Pythagorean theorem applied one dimension at a time. In vector form: whenever u and v are perpendicular, ‖u + v‖2 = ‖u‖2 + ‖v‖2.
This page builds the n-dimensional version step by step, proves the vector version with the dot product, and follows the idea into function spaces, Fourier series and machine learning. It assumes you know the ordinary theorem and the distance formula.
From two dimensions to n dimensions
In two dimensions, a vector (x, y) is the hypotenuse of a right triangle with legs x and y, so its length is √x2 + y2. In three dimensions you use the theorem twice: once across the floor of a box, and once up to the opposite corner.
For the box above, the floor diagonal satisfies d12 = 62 + 32 = 45, and the space diagonal satisfies d2 = d12 + 22 = 49, so d = 7. Notice that you never need d1 itself — the square root cancels — so d2 = 62 + 32 + 22. Whole-number solutions like 2-3-6-7 are called Pythagorean quadruples; the three-dimensional case is covered in detail on the Pythagorean theorem in 3D.
Nothing stops the argument at three. Suppose the formula is true in n − 1 dimensions. Split a vector in ℝn (the space of lists of n real numbers) into two pieces:
(v1, …, vn − 1, vn) = (v1, …, vn − 1, 0) + (0, …, 0, vn)The first piece lies in the first n − 1 coordinate directions and the second points along the last one, so they are perpendicular. The theorem for those two legs, plus the formula already known for n − 1 dimensions, gives
‖v‖2 = (v12 + ⋯ + vn − 12) + vn2 = ∑i = 1nvi2By induction the formula holds in every dimension. The distance between points p and q is the length of p − q: d(p, q) = √∑(pi − qi)2.
Example 1: length of a 4D vector
Find ‖(1, 2, 2, 4)‖.
‖v‖ = √12 + 22 + 22 + 42 = √1 + 4 + 4 + 16 = √25 = 5The length is exactly 5.
Example 2: distance between two points in 4D
Find the distance from p = (1, 0, 3, −2) to q = (4, 4, 3, 10).
d2= (4 − 1)2 + (4 − 0)2 + (3 − 3)2 + (10 − (−2))2= 9 + 16 + 0 + 144 = 169d= 13The points are 13 units apart. You can check 3D distances with the distance formula calculator.
Example 3: the diagonal of a hypercube
A unit cube in n dimensions has corners at (0, …, 0) and (1, …, 1).
d = √12 + 12 + ⋯ + 12 = √nThe diagonal of a unit square is √2, of a unit cube √3, of a 4D tesseract exactly 2, and of a 100-dimensional cube exactly 10 — ten times its edge.
Vectors: orthogonality and the dot product
The coordinate formula hides a cleaner statement. The dot product of two vectors is u · v = u1v1 + u2v2 + ⋯ + unvn, and the squared length of a vector is its dot product with itself: ‖v‖2 = v · v. Two vectors are called orthogonal (perpendicular), written u ⊥ v, when u · v = 0.
Now expand, using the fact that the dot product distributes like ordinary multiplication:
‖u + v‖2= (u + v) · (u + v)= u · u + 2 u · v + v · v= ‖u‖2 + 2 u · v + ‖v‖2Key idea‖u + v‖2 = ‖u‖2 + ‖v‖2 exactly when u · v = 0. That single line is the Pythagorean theorem and its converse, in any number of dimensions.
The middle term 2 u · v is the correction for vectors that are not perpendicular. Writing u · v = ‖u‖‖v‖cosθ turns the same expansion into the law of cosines, and the sign of the dot product tells you whether the angle between the vectors is acute or obtuse — the vector form of classifying triangles by their sides.
Example 4: check orthogonality in 3D
Let u = (1, 2, 2) and v = (2, 1, −2).
u · v= 2 + 2 − 4 = 0‖u‖2 + ‖v‖2= 9 + 9 = 18‖u + v‖2= ‖(3, 3, 0)‖2 = 18The vectors are perpendicular, and the theorem checks out: both sides equal 18.
The theorem extends to any number of mutually orthogonal vectors. If v1, …, vk are pairwise perpendicular, every cross term vanishes and ‖v1 + ⋯ + vk‖2 = ‖v1‖2 + ⋯ + ‖vk‖2. The coordinate formula ∑vi2 is the special case where the vi point along the coordinate axes.
Inner-product spaces: the theorem without coordinates
Mathematicians noticed that the proof above used only three properties of the dot product, so they turned them into a definition. An inner product on a vector space is a rule ⟨u, v⟩ that is symmetric, linear in each slot, and positive (⟨v, v⟩ > 0 unless v = 0). Define length by ‖v‖ = √⟨v, v⟩ and call vectors orthogonal when ⟨u, v⟩ = 0. The same expansion then proves the Pythagorean theorem in every inner-product space.
The "vectors" need not be arrows. Functions on an interval form a vector space, and
⟨f, g⟩ = ∫−ππf(x) g(x) dxis an inner product. With it, sinx and cosx are orthogonal, because ∫−ππsinxcosx dx = 0. Each has squared length π. The theorem predicts ‖sin + cos‖2 = 2π, and a direct calculation agrees: ∫−ππ(sinx + cosx)2dx = ∫−ππ(1 + sin2x) dx = 2π. (The first step uses sin2x + cos2x = 1, the Pythagorean identity.)
Not every length obeys Pythagoras
Some useful ways of measuring length do not come from an inner product. The "taxicab" length ‖(x, y)‖1 = |x| + |y| measures distance along a street grid. For the perpendicular vectors (1, 0) and (0, 1), it gives ‖(1, 1)‖12 = 4, but 12 + 12 = 2. The Pythagorean theorem fails.
There is a sharp test. A norm comes from an inner product exactly when it satisfies the parallelogram law, ‖u + v‖2 + ‖u − v‖2 = 2‖u‖2 + 2‖v‖2 (a theorem of Pascual Jordan and John von Neumann, 1935). The Euclidean norm passes; the taxicab norm does not. In this sense the Pythagorean theorem is what makes Euclidean length special.
Projections and the closest point
One of the theorem's most important jobs is finding the closest point. Let W be a line or plane (more generally, a subspace) through the origin, and let v be any vector. Drop a perpendicular from v to W; its foot p is the orthogonal projection of v onto W.
For any other point w in W, the vector v − p is perpendicular to p − w (which lies in W). By the theorem,
‖v − w‖2 = ‖v − p‖2 + ‖p − w‖2 ≥ ‖v − p‖2So the projection is the closest point of W to v. This is the principle behind least-squares fitting: the best-fit line through data is the projection of the data vector onto the space of possible lines, and "least squares" means least squared Pythagorean distance.
If e1, …, ek are perpendicular unit vectors in W, the projection is p = ∑⟨v, ei⟩ei, and the theorem gives ‖v‖2 = ‖p‖2 + ‖v − p‖2. Dropping the last term yields Bessel's inequality, ∑⟨v, ei⟩2 ≤ ‖v‖2 — a fancy way of saying a leg is never longer than the hypotenuse.
Parseval's identity: Pythagoras in infinitely many dimensions
When the perpendicular unit vectors are numerous enough to build every vector (a complete orthonormal basis), nothing is left over, and Bessel's inequality becomes an equation:
‖v‖2 = ∑i⟨v, ei⟩2This is Parseval's identity, named after Marc-Antoine Parseval, who stated a version for series in a memoir presented in 1799. The sum can have infinitely many terms: it is literally the Pythagorean theorem with infinitely many perpendicular legs. Complete inner-product spaces in which this works are called Hilbert spaces, after David Hilbert.
The classic example is Fourier series. On [−π, π] the functions cosnx and sinnx are mutually orthogonal, and a function can be written as f(x) = a0 over 2 + ∑n ≥ 1(ancosnx + bnsinnx). Parseval's identity then reads
1 over π∫−ππf(x)2 dx = a02 over 2 + ∑n = 1∞(an2 + bn2)Example 5: Pythagoras sums an infinite series
For f(x) = x on (−π, π), all an = 0 and bn = 2(−1)n + 1 over n, so bn2 = 4 over n2. The left side is 1 over π∫−ππx2 dx = 2π2 over 3. Parseval says:
∑n = 1∞4 over n2= 2π2 over 3∑n = 1∞1 over n2= 1 + 1 over 4 + 1 over 9 + ⋯ = π2 over 6 ≈ 1.644934This is the famous Basel problem, first solved by Leonhard Euler in the 1730s by a different method. Here the "hypotenuse" is the function x, and the "legs" are its Fourier components.
The legs add up only gradually: the first Fourier term alone captures about 61% of the squared length, the first 10 terms about 94%, and the first 100 about 99.4%. In signal processing the same identity says that the energy of a signal equals the total energy of its frequency components. It also tells engineers exactly how much error they introduce when they drop the smallest components — the squared error is the sum of the squares of what was dropped — a key idea behind data compression.
Euclidean distance in data science
In machine learning each item — a customer, an image, a song — is often described by a list of numbers called a feature vector, so a dataset is a cloud of points in a high-dimensional space. Euclidean distance, computed with the n-dimensional theorem, measures how similar two items are.
Example 6: how similar are two songs?
Two songs are rated on five features, each on a 0–10 scale: A = (2, 7, 1, 8, 2) and B = (3, 5, 1, 4, 0).
d2= (2 − 3)2 + (7 − 5)2 + (1 − 1)2 + (8 − 4)2 + (2 − 0)2= 1 + 4 + 0 + 16 + 4 = 25d= 5The songs are 5 units apart. A recommendation system would compare this with the distances to other songs and suggest the nearest ones.
- k-nearest neighbors classifies a new point by looking at the closest labeled points.
- k-means clustering groups points so that the total of the squared distances to each group's center is as small as possible — a sum of Pythagorean squares.
- Feature scaling matters: if one feature is measured in dollars and another in kilometers, the large numbers dominate the sum of squares, so data are usually standardized first.
High dimensions also hold surprises, and the theorem explains them. For two random points in the unit cube in n dimensions, each coordinate difference contributes 1 over 6 on average to the squared distance, so the expected squared distance is exactly n over 6. In 1,000 dimensions a typical distance is about 12.9, and the distances between random pairs typically vary by only about 2% around that value. When every point is roughly equally far from every other, "nearest neighbor" loses meaning — part of what data scientists call the curse of dimensionality. Read more on the Pythagorean theorem in computer science.
Other higher-dimensional versions
The norm formula generalizes lengths. There is also a version for areas: in a box-corner tetrahedron, the squared area of the slanted face equals the sum of the squared areas of the three right-angled faces — de Gua's theorem — and it too extends to n dimensions. And if space itself is curved, the formula holds only for very small triangles, as explained on the Pythagorean theorem in non-Euclidean geometry.
Frequently asked questions
Does the Pythagorean theorem work in 4 dimensions?
Yes. The distance from the origin to (w, x, y, z) is √w2 + x2 + y2 + z2, and the same pattern continues in any number of dimensions. You get it by applying the ordinary theorem repeatedly, one new perpendicular direction at a time.
What is the Euclidean norm?
It is the ordinary length of a vector: the square root of the sum of the squares of its components, ‖v‖ = √v12 + ⋯ + vn2. It is also called the L2 norm or 2-norm, and it is the norm that makes the Pythagorean theorem true.
How can I tell if two vectors are orthogonal?
Compute their dot product: multiply matching components and add. If the result is 0, the vectors are orthogonal, and ‖u + v‖2 = ‖u‖2 + ‖v‖2. For example (3, 4) · (−4, 3) = −12 + 12 = 0.
What is the Pythagorean theorem for vectors?
If u ⊥ v, then ‖u + v‖2 = ‖u‖2 + ‖v‖2. It follows from expanding (u + v) · (u + v), and the converse holds too: if the equation is true, the vectors are orthogonal.
What is Parseval's identity in simple terms?
It says that the squared length of a vector equals the sum of the squares of its components along a complete set of perpendicular directions, even when there are infinitely many of them. For Fourier series, it says the energy of a signal equals the sum of the energies of its frequency components.
Why does machine learning use Euclidean distance?
It is the natural straight-line distance between feature vectors, it is easy to compute, and it interacts well with averages and projections — the mean of a set of points is the point that minimizes the total squared distance to them. Other distances (taxicab, cosine) are used when the data call for them.
Sources and further reading
- Sheldon Axler, Linear Algebra Done Right, 4th ed., Springer, 2024 (chapter on inner-product spaces; open access).
- Gilbert Strang, Introduction to Linear Algebra, 6th ed., Wellesley-Cambridge Press, 2023 (orthogonality, projections and least squares).
- P. Jordan and J. von Neumann, "On inner products in linear, metric spaces", Annals of Mathematics 36 (1935).
- Wikipedia: Parseval's theorem.
- Wolfram MathWorld: Pythagorean Theorem.
Keep exploring
- LearnThe Pythagorean Theorem in 3DThe Pythagorean theorem in 3D: find the space diagonal of a box or cube, d = √(l² + w² + h²), with an animated two-step proof, fit problems and 3D distance.
- LearnThe Distance FormulaThe distance formula explained: derive it from the Pythagorean theorem, use it with negative coordinates, avoid sign mistakes and extend it to 3D.
- Real-life usesThe Pythagorean Theorem in Programming and GamesHow programmers use the Pythagorean theorem: distance checks in games, squared distance, circle collisions, Math.hypot, Euclidean distance and float pitfalls.
- LearnDe Gua's TheoremDe Gua's theorem says the squared area of the slanted face of a right-corner tetrahedron equals the sum of the other three. Proofs, examples and history.
- TriplesPythagorean QuadruplesPythagorean quadruples are whole-number boxes with a whole-number space diagonal: full list up to d = 41, how to make them, Euler bricks and the perfect cuboid.
- LearnThe Pythagorean Theorem on a Sphere and in Non-Euclidean GeometryDoes a² + b² = c² hold on a sphere? The spherical and hyperbolic Pythagorean theorems, why they shrink to the usual one for small triangles, and Earth examples.