Average distance of a graph is expressed in terms of its canonical metric representation. The equality can be modified to an inequality in such a way that it characterizes isometric subgraphs of Hamming graphs. This approach simplifies recognition of these graphs and computation of their average distance.