Skip to content

Chessboard distance aka Chebyshev distance

chessboard-distance-aka-chebyshev-distance

Picture a king on a chessboard. It can move one square in any direction, including diagonally. So how many moves does it need to get from one square to another? The answer is the Chebyshev distance, which is why people also call it chessboard distance.

The king’s move

Say the king stands on b2 and wants to reach f5. That is 4 columns across (b to f) and 3 rows up (2 to 5).

Because the king can move diagonally, it can cover a column and a row in the same move. It makes 3 diagonal moves (fixing the rows and 3 of the columns), then 1 more move sideways. Total: 4 moves.

The number of moves is simply the larger of the two gaps: max(4, 3) = 4. That is the whole idea of Chebyshev distance.

The formula

For two points A = (x1, y1) and B = (x2, y2):

D(A, B) = max( |x1 - x2| , |y1 - y2| )

For points with more dimensions, take the largest gap across all of them:

D(A, B) = max over i of |a_i - b_i|

The vertical bars mean “absolute value”, so the gap is never negative.

Worked example

Take A = (2, 7, 1) and B = (5, 3, 2):

DimensionABGap |a − b|
1253
2734
3121

The largest gap is 4, so the Chebyshev distance is 4.

Try it yourself

Chebyshev (Chessboard) Distance Calculator

Enter two vectors (same length), separated by commas or spaces. Example: 1, 2, 3 and 4 5 6.

How to use the calculator

  1. Type the numbers for Vector A, separated by commas or spaces, for example 1, 2, 3.
  2. Type Vector B with the same number of values, for example 4 5 6.
  3. Press Compute.

Quick check

For A = (1, 2, 3) and B = (4, 5, 6), every gap is 3, so the Chebyshev distance is max(3, 3, 3) = 3.

Before you compare real data, scale your features (for example with the z-score calculator), so one large-valued feature doesn't dominate the result.

For the same points, the Euclidean distance is about 5.196.

Chebyshev vs Manhattan vs Euclidean

All three measure distance, but each assumes a different way of moving. For A = (0, 0) and B = (4, 3):

DistanceHow you moveFormula (2D)A to B
ChebyshevAny direction, diagonal costs the same as straight (chess king)max(|Δx|, |Δy|)4
ManhattanOnly along the grid, no diagonals (taxi in city blocks)|Δx| + |Δy|7
EuclideanStraight line (as the crow flies)√(Δx² + Δy²)5

For every pair of points, Chebyshev ≤ Euclidean ≤ Manhattan. To learn more about the straight-line distance, read As the crow flies: Euclidean distance.

Where Chebyshev distance is used

  • Warehouse robots and cranes that move along two axes at the same time: the travel time depends on the slower axis, which is the larger gap.
  • Image processing: finding the 8 pixels around a pixel (its neighbours, diagonals included) uses Chebyshev distance 1.
  • Games and grid maps: working out moves for pieces that can travel diagonally.
  • Quality checks and finance: when only the single worst deviation matters, for example “no reading may be off by more than 2 units”.
  • Machine learning: k-nearest neighbours (kNN) in scikit-learn accepts metric="chebyshev".

Try it in Python

from scipy.spatial.distance import chebyshev

A = [2, 7, 1]
B = [5, 3, 2]
print(chebyshev(A, B))  # 4

# without SciPy
print(max(abs(a - b) for a, b in zip(A, B)))  # 4

When not to use it

Chebyshev only looks at the largest gap and ignores the rest. Points (0, 0) → (4, 0) and (0, 0) → (4, 4) both have distance 4, even though the second is clearly further in a straight line. If every dimension should count, Euclidean or Manhattan is usually a better choice. As with the other distances, scale your features first so one large-valued feature doesn’t dominate.

Summary

Chebyshev distance is the largest gap between two points in any single dimension. It matches how a chess king moves, it is quick to calculate, and it suits problems where only the worst-case difference matters.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

One short email when a new calculator or article goes live. No spam, and you can unsubscribe in one click.