MathApril 12, 2026

Distance Calculator Guide: Distance Formula in 2D and 3D (2026)

By The hakaru Team·Last updated March 2026

Quick Answer

  • *2D distance: d = √((x₂ − x₁)² + (y₂ − y₁)²)
  • *3D distance: add a z-term: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
  • *Derived from the Pythagorean theorem — distance is the hypotenuse of a right triangle.
  • *Manhattan distance measures grid-based paths: d = |x₂ − x₁| + |y₂ − y₁|

The Distance Formula in 2D

The distance between two points (x₁, y₁) and (x₂, y₂) in a plane is:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

This is the Pythagorean theorem in disguise. The horizontal distance (x₂ − x₁) and vertical distance (y₂ − y₁) form two legs of a right triangle. The straight-line distance between the points is the hypotenuse.

Worked Example

Find the distance between (1, 2) and (4, 6):

  • d = √((4 − 1)² + (6 − 2)²) = √(9 + 16) = √25 = 5

The Distance Formula in 3D

Add the z-dimension:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Distance between (1, 2, 3) and (5, 6, 7): d = √(16 + 16 + 16) = √48 ≈ 6.93

Manhattan Distance

Also called taxicab distance or L1 norm, Manhattan distance measures the path you'd travel along a grid — no diagonal shortcuts:

d = |x₂ − x₁| + |y₂ − y₁|

Between (1, 2) and (4, 6): d = |4 − 1| + |6 − 2| = 3 + 4 = 7 (compared to Euclidean distance of 5). Manhattan distance is always ≥ Euclidean distance.

When to Use Each Distance

Distance TypeFormulaBest For
Euclidean (L2)√(Σ(xᵢ − yᵢ)²)Straight-line distance, geometry, physics
Manhattan (L1)Σ|xᵢ − yᵢ|Grid navigation, sparse data, feature selection
Chebyshev (L∞)max(|xᵢ − yᵢ|)Chess king moves, warehouse logistics

Distance vs. Displacement

Distance is scalar — it measures how far, always positive. Displacement is a vector — it measures how far and in what direction from start to finish. If you walk 3 blocks east then 3 blocks west, your distance is 6 blocks but your displacement is 0. The distance formula calculates displacement magnitude.

Applications

  • Navigation and GPS: Haversine formula extends the concept to spherical coordinates for Earth distances.
  • Machine learning: K-nearest neighbors, clustering, and similarity metrics all use distance calculations.
  • Game development: Collision detection, pathfinding, and range checks.
  • Physics: Force fields, orbital mechanics, electromagnetic calculations.

Calculate distance between any two points

Try the Free Distance Calculator →

Frequently Asked Questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). It's derived from the Pythagorean theorem — the distance is the hypotenuse of a right triangle formed by the coordinate differences.

How do you calculate distance in 3D?

Add a z-component: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). Used in 3D modeling, physics, and aviation.

What is Manhattan distance?

Distance along grid lines: d = |x₂ − x₁| + |y₂ − y₁|. Named after Manhattan's grid layout. Used in logistics, pathfinding, and machine learning.

What is the difference between distance and displacement?

Distance is total path length (always positive). Displacement is straight-line distance with direction (can be zero). The distance formula calculates displacement magnitude.

Can the distance formula give a negative result?

No. Squaring makes differences positive, and the square root is non-negative. The minimum distance is zero (when both points are identical).