Theory
Coordinates locate the endpoints, but the straight segment between them may be diagonal. Counting grid squares along the diagonal is not reliable: first find how far across and how far up or down the endpoints are.
For A(-2, 1) and B(1, 5), go 3 units right from -2 to 1 and 4 units up from 1 to 5. Draw these horizontal and vertical moves as the two shorter sides of a right-angled triangle. The segment AB is its longest side, called the hypotenuse.
Pythagoras' theorem says hypotenuse² = horizontal change² + vertical change². Here AB² = 3² + 4² = 9 + 16 = 25, so AB = √25 = 5 units. The sketch shows why you add the squares; you do not add 3 and 4 to get the diagonal.
You can calculate each change by subtracting the endpoint coordinates: horizontal change = |x₂ - x₁| and vertical change = |y₂ - y₁|. The absolute-value bars mean take the positive size of the move. For A(-4, -1) to B(2, 7), the changes are 6 and 8, so the length is √(6² + 8²) = 10 units.
If both points share an x-coordinate or a y-coordinate, the segment is vertical or horizontal: just count that one change. If the square root does not simplify to a whole number, keep an exact surd unless the question asks for a decimal approximation. Label any real-world length with its unit.