Manhattan distance calculator
Enter the coordinates of two points or vectors with the same number of components. The calculator adds up the absolute differences to give the Manhattan distance and shows the Euclidean, Chebyshev and Minkowski distances for the same pair, so you can compare the metrics side by side.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Enter the coordinates of A, separated by spaces or commas. Any number of dimensions works.
- Enter B with the same number of coordinates.
- Optionally change p for the Minkowski distance. The Manhattan distance is the main result; the other metrics are listed below it.
With dᵢ = aᵢ − bᵢ:
- Manhattan L1 = Σ |dᵢ|
- Euclidean L2 = √(Σ dᵢ²)
- Chebyshev L∞ = max |dᵢ|
- Minkowski Lp = (Σ |dᵢ|ᵖ)^(1/p), p ≥ 1
Worked example
A = (1, 2, 3), B = (4, 0, 3):
- Absolute differences: 3, 2, 0.
- Manhattan: 3 + 2 + 0 = 5.
- Euclidean: √(9 + 4 + 0) = 3.605551.
- Chebyshev: 3.
- Minkowski with p = 3: (27 + 8 + 0)^(1/3) = 3.271066.
As expected, L∞ ≤ L3 ≤ L2 ≤ L1.
Tips
- Scale features first. If one coordinate is in metres and another in millimetres, the larger numbers dominate every metric.
- Grid paths: on a city grid or a pixel grid with 4-way moves, the Manhattan distance is the shortest number of steps when nothing blocks the way.
- For similarity of directions rather than positions, the cosine similarity calculator is the better tool.
Frequently asked questions
What is the Manhattan distance?
The sum of the absolute differences of the coordinates: |x₁ − x₂| + |y₁ − y₂| + … It is the distance a taxi drives on a grid of streets, moving only along the axes, which is where the names taxicab and city-block distance come from.
How is it different from the Euclidean distance?
Euclidean distance is the straight line, √Σ(aᵢ − bᵢ)². Manhattan distance is never shorter: from (0, 0) to (3, 4) the straight line is 5 but the grid route is 7. They are equal only when the points differ in a single coordinate.
When should I use Manhattan distance?
When movement follows axes (grids, warehouse aisles, chess rooks), when features are on different scales and you want each to count linearly, and in k-nearest neighbours or k-medians clustering on high-dimensional data, where L1 is often less dominated by a single large gap than L2.
What are Chebyshev and Minkowski distances?
Chebyshev is the largest single coordinate difference, the number of moves a chess king needs. Minkowski is the general family (Σ|aᵢ − bᵢ|ᵖ)^(1/p): p = 1 gives Manhattan, p = 2 Euclidean, and as p grows it approaches Chebyshev.