Manhattan Distance Calculator
Calculate the Manhattan or taxicab distance between two points, the sum of the horizontal and vertical gaps.
Compares it to the straight-line distance.
Manhattan distance measures how far apart two points are if you can only move along the grid, never diagonally. You add the horizontal gap and the vertical gap: the absolute value of x2 minus x1, plus the absolute value of y2 minus y1. The name comes from a city laid out in blocks, where a taxi cannot cut through buildings and has to drive along the streets and avenues, so it is also called taxicab distance or L1 distance.
That makes it different from the straight-line distance you get from the Pythagorean theorem, which is the shortest possible path as the crow flies. The straight-line distance is always shorter than or equal to the Manhattan distance, and they only match when the two points share a row or a column. For a point three blocks east and four blocks north, the taxicab distance is seven blocks while the straight-line distance is five.
Why use it instead of the usual distance? In a lot of real problems diagonal movement is not allowed or not meaningful. Pathfinding on a square grid, a rook moving on a chessboard, warehouse robots running down aisles, and pixel operations on a screen all behave like a taxicab. It also shows up constantly in machine learning, where L1 distance is a common way to compare feature vectors and tends to be less sensitive to a single large outlier than the squared terms in straight-line distance. This calculator gives you the Manhattan distance plus the Euclidean and Chebyshev distances side by side, so you can see how the three metrics differ for the same pair of points.