Advertisement
Advertisement
DISTANCE METRICS

Manhattan Distance Calculator — taxicab distance in any number of dimensions

Sum the absolute coordinate differences between two points of any dimension, with Euclidean, Chebyshev and Minkowski distances computed alongside for comparison.

Separate values with commas, spaces or tabs. Anything from 1 to 20 dimensions. These need not be spatial coordinates — feature vectors work identically.
Must have the same number of components as point A. A mismatch is reported rather than silently padded with zeros.
p = 1 reproduces the Manhattan distance, p = 2 the Euclidean, and p rising without bound approaches the Chebyshev.
Arithmetic is full double precision; this controls the display only.
Manhattan distance, L₁
 
Euclidean, L₂
Chebyshev, L∞
Minkowski at your p
Dimensions
Working:
Tip: the bar panel shows which coordinate contributes most to the Manhattan total. Because L₁ adds the differences rather than squaring them, no single axis can dominate the way it does under a Euclidean measure, which is exactly why L₁ is preferred where one outlying feature should not swamp the rest.
Advertisement

The Manhattan distance calculator above sums the absolute differences between corresponding coordinates of two points, in as many dimensions as you give it. It reports the Euclidean, Chebyshev and Minkowski distances at the same time, because the interesting question is rarely what one metric says but how far the metrics disagree on the same pair of points.

Arb Digital publishes it as a metric-family tool rather than a spatial one. Our 3D distance calculator is the right page for the straight-line separation of two points in physical space, where Euclidean is the headline answer and three dimensions are the whole subject. This page keeps L₁ as the headline and takes vectors of any length, which is the shape the problem has in clustering, routing and feature comparison.

What This Manhattan Distance Calculator Does

It parses two lists of numbers, checks they are the same length, and computes four distances between them. The Manhattan or taxicab distance is the sum of the absolute coordinate differences. The Euclidean is the square root of the sum of their squares. The Chebyshev is the largest single difference. The Minkowski at exponent p is the p-th root of the sum of the p-th powers, which contains the other three as the cases p = 1, p = 2 and p growing without bound.

Alongside the totals it breaks out the per-axis contribution, which is where the practical insight usually lives. If one coordinate supplies eighty per cent of the Manhattan total, that coordinate is effectively deciding the answer, and whether that is correct depends entirely on whether the coordinates are on comparable scales. Feeding a metric one feature measured in millimetres and another in kilometres produces a number that means very little.

Two edge cases get written answers. Vectors of different lengths are refused with the two lengths named, because padding the shorter one with zeros would silently change the answer. Identical points return zero, and the tool says so explicitly rather than leaving four zeros for you to interpret.

How to Use It

  1. Enter both points as lists of numbers separated by commas or spaces. Any dimension from 1 to 20 works.
  2. Check the dimension cell matches what you expected. A stray separator produces an extra component and a wrong answer.
  3. Compare the four distances. They will always order themselves with Chebyshev smallest and Manhattan largest, and how wide that spread is tells you how concentrated the differences are.
  4. Set p to see the Minkowski family interpolate. Watch the value slide from the Manhattan total towards the Chebyshev as p rises.
  5. Read the per-axis bars to find out which coordinate is driving the result before you trust it.

The Formula and How It Is Calculated

The Manhattan distance between points x and y is i |xi − yi|. Wolfram MathWorld's page on the taxicab metric states the two-dimensional case as |x₁ − x₂| + |y₁ − y₂| and describes it as the length of any path connecting the points along horizontal and vertical segments. The extension to n dimensions is the obvious one: keep adding terms.

Equivalently it is the L₁ norm of the difference vector. MathWorld's page on the L₁ norm defines that norm as the sum of the absolute values of the components, which is exactly the same arithmetic applied to x minus y. Every metric on this page is a norm of the difference vector in the same way.

Work the default. A is (1, 2, 3, 4) and B is (5, 7, 2, 10), so the absolute differences are 4, 5, 1 and 6. The Manhattan distance is 4 + 5 + 1 + 6 = 16. The Euclidean is √(16 + 25 + 1 + 36) = √78 = 8.8317609. The Chebyshev is the largest difference, 6. The Minkowski at p = 3 is the cube root of 64 + 125 + 1 + 216 = 406, which is 7.4047206. Notice how the four sit in order and how p = 3 lands between the Euclidean and the Chebyshev.

Advertisement

The Inequalities That Always Hold

For any pair of points in n dimensions, L∞ ≤ L₂ ≤ L₁. That ordering is not a coincidence of the example: raising numbers below one to a higher power shrinks them, and taking the higher root shrinks the total further, so larger p always gives a smaller or equal distance. The Chebyshev is the limiting case where only the largest single difference survives.

There is a bound in the other direction too. L₁ is at most √n times L₂, with equality exactly when all the coordinate differences are equal. For the default four-dimensional example that bound is 2 × 8.8317609 = 17.6635, against an actual L₁ of 16 — fairly close, because the differences 4, 5, 1, 6 are not far from uniform. If one difference dominated, L₁ and L₂ would nearly coincide instead.

That relationship is the reason the metrics diverge most in high dimensions, and it underpins the well-known observation that distances become less discriminating as dimension grows. In a hundred dimensions of comparable noise, every pair of points ends up at a similar Euclidean distance, while the Manhattan distance retains slightly more contrast — which is one reason L₁ is often preferred for high-dimensional nearest-neighbour work.

When Manhattan Is the Right Metric

The obvious case is movement restricted to axes. On a street grid, in a warehouse with rectangular aisles, or for a robot arm with independent orthogonal joints, the reachable path length is the sum of the axis moves and not the diagonal. Euclidean distance is then a lower bound that no vehicle can actually achieve, which makes it the wrong number to plan with.

The less obvious case is where you deliberately want a single large difference to matter less. Squaring differences, as Euclidean does, gives disproportionate weight to the largest one; adding them treats every unit of difference equally regardless of which axis it sits on. In regression this is the difference between least absolute deviations and least squares, and it is exactly why the former is more robust to outliers.

The same logic applies to comparing feature vectors. If one attribute of a record is wildly different while the rest match closely, Euclidean distance will call the records far apart and Manhattan will call them moderately apart. Which is correct depends on whether that one attribute is meaningful or noisy. Our vector calculator handles the underlying vector arithmetic, and our coordinates converter converts between systems before you measure.

What This Page Is Not Measuring

It is not a string comparison. Our Hamming distance calculator counts the positions at which two equal-length sequences of symbols disagree, which is a completely different operation: it asks whether corresponding entries match, not how far apart they are numerically. Two coordinates of 1 and 1,000 contribute 999 here and contribute exactly 1 to a Hamming distance.

It is also not a distance on a sphere. Applying any of these metrics to latitude and longitude treats degrees as if they were flat, equal-sized units, which they are not — a degree of longitude shrinks towards the poles. For anything geographic use our great circle distance calculator, which works on the sphere.

One naming trap is worth flagging. In relativity, "Minkowski metric" means the spacetime interval with its mixed signs, an entirely different object from the Lp family called the Minkowski distance in data analysis. The names collide, the mathematics does not, and a reference page for one will not tell you anything about the other.

Need a metric tool that shows the breakdown?

Arb Digital builds free maths tools that show which component drove the answer, not just the total.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Mixing scales across coordinates — a metric on unstandardised features is dominated by whichever attribute happens to have the largest units, regardless of its importance.
  • Forgetting the absolute values — signed differences cancel, so a point that is 5 above on one axis and 5 below on another would come out at zero distance.
  • Using Euclidean for grid-constrained movement — the straight line is a lower bound nothing can travel, so it understates every real route on a rectangular network.
  • Applying any of these to latitude and longitude — degrees are not equal-sized units, and a spherical formula is needed instead.
  • Confusing Manhattan with Hamming — one adds numerical gaps, the other counts positions that differ at all. They agree only on binary vectors.

Related Free Tools From Arb Digital

Measure straight-line separation in space with the 3D distance calculator, count differing positions in two sequences with the Hamming distance calculator, measure across the globe with the great circle distance calculator, do the underlying vector arithmetic with the vector calculator, or change coordinate systems first with the coordinates converter. The full free online tools hub lists every geometry tool we publish.

Frequently Asked Questions

What is the Manhattan distance?

The sum of the absolute differences between corresponding coordinates of two points. It is also called the taxicab or L1 distance, and it measures the length of a path that moves only along the axes.

How many dimensions can this handle?

Up to twenty. The formula simply adds one term per dimension, so nothing about it is specific to two or three, and feature vectors work exactly like spatial coordinates.

Is Manhattan distance always larger than Euclidean?

Larger or equal, always. The two coincide only when at most one coordinate differs; otherwise squaring and taking the root shrinks the total relative to plain addition.

What is the Chebyshev distance?

The largest single coordinate difference, ignoring all the others. It is the limit of the Minkowski distance as the exponent grows without bound, and it is the smallest of the three metrics shown here.

What does the Minkowski exponent do?

It interpolates between the metrics. An exponent of 1 gives the Manhattan distance, 2 gives the Euclidean, and larger values move steadily towards the Chebyshev by weighting the biggest difference more heavily.

When should I use Manhattan rather than Euclidean?

When movement is restricted to the axes, or when you want a single large difference on one coordinate to count no more heavily than the same total spread across several.

Is this the same as Hamming distance?

No. Hamming counts how many positions differ at all, regardless of by how much. The two agree only on binary vectors, where every difference is either zero or one.

Can I use it on latitude and longitude?

Not meaningfully. Degrees of longitude cover different ground distances at different latitudes, so a flat metric distorts the result. Use a great circle formula for geographic work.

This page explains a family of distance metrics for educational purposes. Which metric is appropriate is a modelling decision about the data and the movement it represents, and no calculator can make that choice for you.

Advertisement
Advertisement

Take it further