Skip to content
Math

Manhattan Distance Calculator

Enter the coordinates of two points to find the Manhattan distance between them. Choose 2D, 3D, or 4D space, and the calculator shows the exact L1 distance alongside the Euclidean (L2) distance for comparison. Every absolute-difference step is shown so you can follow the arithmetic exactly.

Your details

How many coordinate axes your points live on.
x-coordinate of the first point.
y-coordinate of the first point.
x-coordinate of the second point.
y-coordinate of the second point.
Manhattan Distance
8

L1 norm: sum of absolute coordinate differences

Euclidean Distance5.6569
Manhattan / Euclidean ratio1.4142
|Ax - Bx|4
|Ay - By|4
|Az - Bz|-
|Aw - Bw|-
|Ax - Bx|4
|Ay - By|4

Manhattan distance between the two 2D points is 8.0000.

  • The straight-line (Euclidean) distance is 5.6569, so the Manhattan path is 1.41x as long.
  • In a city grid, this is the minimum number of blocks you must walk to get from Point A to Point B, regardless of which route you take.
  • Any path that only goes right/left and up/down (no diagonals) will cover exactly this distance.

Next stepUse Manhattan distance when movement is constrained to a grid (city blocks, chess rooks, pixels). Use Euclidean when direct travel through open space is possible.

Formula

dManhattan=i=1naibi=x1x2+y1y2+d_{\text{Manhattan}} = \sum_{i=1}^{n} |a_i - b_i| = |x_1-x_2| + |y_1-y_2| + \cdots

Worked example

Points A(1, 2) and B(5, 6): |1-5| + |2-6| = 4 + 4 = 8. The Euclidean distance is sqrt(16 + 16) = 5.657. The Manhattan path is 8 / 5.657 = 1.414x longer, which is always sqrt(2) when movement is equally split across two axes.

What is Manhattan distance?

Manhattan distance is the sum of the absolute differences between the coordinates of two points. For two points A(x1, y1) and B(x2, y2) on a plane, the Manhattan distance is |x1 - x2| + |y1 - y2|. The name comes from the grid layout of Manhattan streets: if you can only walk along streets and avenues (no cutting through buildings), the shortest possible path between any two intersections is exactly the Manhattan distance, regardless of which specific route you choose. It is also called the L1 norm, taxicab distance, or city-block distance.

Manhattan distance vs. Euclidean distance

Euclidean distance measures the straight-line distance between two points - what you get with a ruler. Manhattan distance measures the grid-constrained distance - what you get walking along a street grid. For movement purely along one axis, both are identical. For diagonal movement, the Euclidean distance is shorter: the worst case is when movement is split equally across all axes, where Manhattan distance is sqrt(n) times the Euclidean distance for n dimensions. In practice, choose Manhattan distance when your system can only move along coordinate axes (grid maps, pixels, chess rooks, 3D printers, warehouse robots), and Euclidean distance when straight-line travel is possible (GPS, radar, physics simulations, most geometric problems).

Real-world applications

Manhattan distance appears in many practical fields. In machine learning, L1-distance underpins k-nearest-neighbor classifiers, and L1 regularization (Lasso) shrinks model coefficients toward zero more aggressively than L2, producing sparser models. In robotics and logistics, warehouse robots on grid systems minimize Manhattan distance to plan routes. In image processing, pixel-level operations often use taxicab geometry because pixels sit on a grid. In board games, a chess rook moves along ranks and files, so Manhattan distance is the minimum number of moves needed (ignoring blocking pieces). In bioinformatics, Manhattan distance between gene expression vectors provides a robust similarity metric that is less sensitive to extreme outliers than Euclidean distance.

Extending to 3D and 4D space

The formula generalizes directly to any number of dimensions: add one absolute-difference term per axis. In 3D, d = |x1-x2| + |y1-y2| + |z1-z2|, which applies to 3D grid navigation, voxel-based rendering, and 3D robotics. In 4D feature space - common in machine learning with four-feature datasets - d = |x1-x2| + |y1-y2| + |z1-z2| + |w1-w2|. The ratio of Manhattan to Euclidean distance grows with the number of dimensions (up to sqrt(n)), a phenomenon related to the "curse of dimensionality" that affects distance-based algorithms in high-dimensional spaces.

Manhattan vs. Euclidean distance: key properties

PropertyManhattan (L1)Euclidean (L2)
Formulasum of |differences|sqrt of sum of squares
GeometryTaxicab / city-block pathsStraight-line distance
Sensitivity to outliersLower (linear in each axis)Higher (squares each diff)
Best for gridsYes - robots, maps, chessNo - penalizes diagonal routes
Best for continuous spaceAcceptableYes - radar, GPS, physics
Machine learning useL1 regularization, k-NNk-NN, SVM, PCA
Max ratio vs Euclideansqrt(n) for n dimensions1 (baseline)

Both are proper distance metrics satisfying non-negativity, symmetry, identity, and the triangle inequality.

Frequently asked questions

What is Manhattan distance?

Manhattan distance is the sum of the absolute differences between two points across each coordinate axis. For a 2D plane it is |x1-x2| + |y1-y2|. It represents the distance you would walk on a city block grid where only horizontal and vertical movement is allowed, hence the name taxicab or city-block distance.

How is Manhattan distance different from Euclidean distance?

Euclidean distance is the straight-line (ruler) distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2). Manhattan distance adds up absolute differences without squaring: |x1-x2| + |y1-y2|. Manhattan distance is always greater than or equal to Euclidean distance. When movement is constrained to a grid, use Manhattan. When straight-line travel is possible, use Euclidean.

Is Manhattan distance always larger than Euclidean distance?

Yes, always. The triangle inequality guarantees that the direct (Euclidean) path is never longer than any other path, including the grid-constrained one. The two are equal only when the two points differ on exactly one axis. The maximum ratio is sqrt(n) for n-dimensional points, achieved when both points are spread equally across all axes.

When should I use Manhattan distance in machine learning?

Manhattan distance (L1 norm) is a good choice for k-nearest neighbor classification when features are on different scales or when you want less sensitivity to outliers compared to Euclidean distance. L1 regularization (Lasso regression) uses the Manhattan norm to penalize model weights and tends to produce sparse solutions where unimportant features are driven to exactly zero.

Can this calculator handle 3D and 4D coordinates?

Yes. Use the Dimensions selector to choose 2D, 3D, or 4D. The z and w coordinate fields appear only when the appropriate dimension is selected. The formula sums one absolute-difference term per axis, so adding more dimensions simply adds more terms.

What does the Manhattan/Euclidean ratio tell me?

The ratio shows how much longer the constrained grid path is compared to the straight-line path. A ratio of 1.0 means both points lie on the same axis. A ratio near 1.414 (sqrt(2)) means the two points differ equally on two axes. The ratio can never exceed sqrt(n) for n dimensions. A high ratio indicates the points are spread diagonally, while a low ratio means movement is nearly axis-aligned.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…