Euclidean Distance Calculator
Enter the coordinates of two points and choose how many dimensions to work in. The calculator finds the straight-line (Euclidean) distance between them, shows every step of the arithmetic, and adds the Manhattan distance for comparison. Switch between 2D, 3D and 4D mode as needed. Results update as you type.
Formula
Worked example
Points A = (1, 2) and B = (4, 6) in 2D: dx = 4 - 1 = 3, dy = 6 - 2 = 4. Squared sum = 3² + 4² = 9 + 16 = 25. Distance = sqrt(25) = 5. This is a classic 3-4-5 right triangle.
What is Euclidean distance?
Euclidean distance is the length of the straight line segment connecting two points in ordinary geometric space. The name comes from Euclid, whose geometry axioms underpin the familiar "shortest path between two points is a straight line." In two dimensions the formula is a direct application of the Pythagorean theorem: d = sqrt((x2 - x1)² + (y2 - y1)²). In three dimensions a third squared difference is added under the root, and the pattern continues to any number of dimensions. This generalization - the Euclidean metric - is the default distance measure in mathematics, physics, machine learning, geographic information systems, and computer graphics.
How to use this calculator
Select the number of dimensions (2D, 3D or 4D) from the dropdown. Enter the x and y coordinates of your two points (and z or z and w if you chose a higher dimension). The calculator instantly returns the Euclidean distance, the squared distance, the Manhattan (city-block) distance, and the individual axis differences. The "Show your work" panel traces every arithmetic step so you can verify the calculation by hand. Default values (A = (1, 2) and B = (4, 6)) give the textbook 3-4-5 triangle result of 5, a useful sanity check.
Euclidean vs. Manhattan distance
Euclidean distance measures the straight-line path - the crow flies. Manhattan distance (also called taxicab or city-block distance) sums the absolute differences along each axis separately, as if you could only travel along grid lines. For any two distinct points, the Euclidean distance is always less than or equal to the Manhattan distance (they are equal only in one dimension, or when the points differ on exactly one axis). The ratio approaches 1/sqrt(2) in 2D when the two points lie on a 45-degree diagonal. In machine learning, the choice between the two norms affects how nearest-neighbor algorithms and clustering algorithms define "closeness."
Practical applications
Euclidean distance appears across many fields. In GIS and mapping it is the straight-line distance between coordinates (before accounting for the Earth's curvature - for large geographic distances use the Haversine formula instead). In machine learning it drives k-nearest-neighbors classification, k-means clustering, and similarity search in vector databases. In physics it gives the straight-line distance between two positions in space. In computer graphics and game development it is used for collision detection and line-of-sight checks. In robotics and path planning the squared distance is preferred because it avoids a square-root operation and maintains the same ranking order.
Euclidean distance formulas by dimension
| Dimensions | Formula | Classic example |
|---|---|---|
| 1D | d = |x2 - x1| | |7 - 3| = 4 |
| 2D | d = sqrt((x2-x1)² + (y2-y1)²) | A(1,2), B(4,6) -> d = 5 |
| 3D | d = sqrt((x2-x1)² + (y2-y1)² + (z2-z1)²) | A(0,0,0), B(2,3,6) -> d = 7 |
| 4D | d = sqrt(dx² + dy² + dz² + dw²) | A(0,0,0,0), B(1,2,2,4) -> d = 5 |
| nD | d = sqrt(sum of squared differences) | Generalizes via Pythagorean theorem |
The same square-root-of-sum-of-squares pattern extends to any number of dimensions.
Frequently asked questions
What is the Euclidean distance formula?
For two points in n-dimensional space, d = sqrt of the sum of the squared differences for each coordinate: d = sqrt((x2-x1)² + (y2-y1)² + ...). In 2D this reduces to the Pythagorean theorem. In 3D a third term (z2-z1)² is added under the square root.
Why use squared distance instead of Euclidean distance?
Computing a square root is more expensive than squaring, and for comparing or ranking distances the square root is not needed because the ordering is preserved - if d1 < d2 then d1² < d2² as well. Machine learning algorithms such as k-nearest neighbors and k-means often use squared Euclidean distance internally for this reason.
What is the difference between Euclidean and Manhattan distance?
Euclidean distance is the straight-line (crow-flies) distance. Manhattan distance adds up the absolute differences along each axis, like walking along city blocks where you can only go north-south or east-west. Euclidean distance is always less than or equal to Manhattan distance for the same pair of points.
Does this calculator work for GPS or geographic coordinates?
For small distances (a few kilometers or less) treating latitude and longitude as flat 2D coordinates gives a reasonable approximation. For larger distances you need to account for the curvature of the Earth using the Haversine formula, because the Earth is a sphere and degrees of longitude shrink toward the poles.
How do I calculate Euclidean distance in higher dimensions?
The pattern is the same regardless of dimension: subtract the corresponding coordinates of the two points, square each difference, add all the squared differences together, then take the square root. This calculator handles up to 4D. For higher dimensions the arithmetic is identical - just keep adding squared differences.
What is the Euclidean norm?
The Euclidean norm (also called the L2 norm) of a vector is its length from the origin, which equals the Euclidean distance from the origin to the tip of the vector. For a vector v = (a, b, c), the norm is sqrt(a² + b² + c²). Computing the distance between two points is equivalent to computing the norm of the difference vector.