Length of a Line Segment Calculator

Length of a Line Segment Calculator

Popular AI Skill PRO

Enter Calculation

Results

Length of the Line Segment
5
units
Horizontal change 3
Vertical change 4

Formula

L=(x2−x1)2+(y2−y1)2L = \sqrt{\left({{\text{x}_2}} - {{\text{x}_1}}\right)^2 + \left({{\text{y}_2}} - {{\text{y}_1}}\right)^2}

Example

L=(3−0)2+(4−0)2=5L = \sqrt{\left(3 - 0\right)^2 + \left(4 - 0\right)^2} = 5
Usage stats

Advertisement

Report an error on this page

What Is the Length of a Line Segment?

A line segment is the portion of a straight line bounded by two endpoints. Its length is simply the straight-line distance between those two endpoints. When the points are given as coordinates in the Cartesian plane, you can find this length exactly using the distance formula, which is a direct application of the Pythagorean theorem.

A line segment between two labeled points on a coordinate plane
A line segment connecting points (x₁,y₁) and (x₂,y₂) on the coordinate plane.

How to Use This Calculator

Enter the coordinates of the first endpoint as (x₁, y₁) and the second endpoint as (x₂, y₂). The calculator subtracts the coordinates to find the horizontal change (Δx) and vertical change (Δy), squares each, adds them, and takes the square root to return the segment length. Coordinates can be positive, negative, or decimal values.

The Formula Explained

The length is given by:

$$L = \sqrt{\left(x_2 - x_1\right)^2 + \left(y_2 - y_1\right)^2}$$

The differences \((x_2 - x_1)\) and \((y_2 - y_1)\) form the two legs of a right triangle, and the segment itself is the hypotenuse. Squaring removes any negative signs, so the order in which you subtract does not affect the result.

Advertisement
Right triangle showing horizontal and vertical legs forming the distance formula
The distance formula comes from the Pythagorean theorem using the horizontal and vertical differences.

Worked Example

Find the length between A(1, 2) and B(4, 6). Here \(\Delta x = 4 - 1 = 3\) and \(\Delta y = 6 - 2 = 4\). So $$L = \sqrt{3^2 + 4^2} = \sqrt{9 + 16} = \sqrt{25} = 5 \text{ units}.$$ This is the classic 3-4-5 right triangle.

More Worked Examples

Each example uses \(L = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\).

Example 1: Negative coordinates

Find the length of the segment from \((-2, -1)\) to \((2, 2)\).

  1. \(\Delta x = 2 - (-2) = 4\)
  2. \(\Delta y = 2 - (-1) = 3\)
  3. Squares: \(4^2 = 16\) and \(3^2 = 9\)
  4. Sum: \(16 + 9 = 25\)
  5. Square root: \(L = \sqrt{25} = \) 5

Subtracting a negative coordinate adds its magnitude, so take care with signs. Squaring removes any negative sign afterward.

Example 2: A non-perfect-square result

Find the length from \((0, 0)\) to \((1, 1)\).

  1. \(\Delta x = 1 - 0 = 1\)
  2. \(\Delta y = 1 - 0 = 1\)
  3. Squares: \(1^2 = 1\) and \(1^2 = 1\)
  4. Sum: \(1 + 1 = 2\)
  5. Square root: \(L = \sqrt{2} \approx 1.4142\)

This is the diagonal of a unit square. The exact answer is \(\sqrt{2}\), which is irrational, so the decimal is a rounded value.

Example 3: A vertical segment

Find the length from \((3, 5)\) to \((3, 11)\).

  1. \(\Delta x = 3 - 3 = 0\)
  2. \(\Delta y = 11 - 5 = 6\)
  3. Squares: \(0^2 = 0\) and \(6^2 = 36\)
  4. Sum: \(0 + 36 = 36\)
  5. Square root: \(L = \sqrt{36} = \) 6

When one difference is zero, the formula reduces to the absolute value of the other difference: \(L = |y_2 - y_1| = 6\).

Comparing Different Segment Types

The same formula covers every orientation of a segment. This table compares common cases.

Scenario Point 1 Point 2 Δx Δy Length
Horizontal (1, 2) (7, 2) 6 0 6
Vertical (4, −3) (4, 5) 0 8 8
Diagonal 45° (0, 0) (3, 3) 3 3 3√2 ≈ 4.243
3-4-5 triangle (0, 0) (3, 4) 3 4 5
Identical points (2, 2) (2, 2) 0 0 0

Notes: horizontal and vertical segments need only a single subtraction. A 45° diagonal has \(\Delta x = \Delta y\), so its length is \(|\Delta x|\sqrt{2}\). If both points are the same, the segment has zero length (a degenerate segment).

Advertisement

Key Terms and Symbols

  • Line segment: the part of a straight line between two endpoints, including both endpoints. It has a finite, measurable length.
  • Endpoint: one of the two points that bound a segment, written as \((x_1, y_1)\) and \((x_2, y_2)\).
  • Coordinate plane: a two-dimensional grid where each point is located by an ordered pair \((x, y)\) measured from the origin along a horizontal x-axis and a vertical y-axis.
  • Δx and Δy: the changes in the horizontal and vertical coordinates, \(\Delta x = x_2 - x_1\) and \(\Delta y = y_2 - y_1\). They are the legs of the right triangle underlying the formula.
  • Hypotenuse: the side opposite the right angle in a right triangle, and the longest side. The segment itself is the hypotenuse of the triangle with legs \(|\Delta x|\) and \(|\Delta y|\).
  • Pythagorean theorem: in a right triangle with legs \(a\), \(b\) and hypotenuse \(c\), \(a^2 + b^2 = c^2\). The distance formula is this theorem applied to coordinates.
  • Euclidean distance: the ordinary straight-line distance between two points in flat space, which is what this calculator computes.
  • Segment vs. ray vs. line: a segment has two endpoints and a finite length. A ray has one endpoint and extends forever in one direction. A line extends forever in both directions, so neither a ray nor a line has a finite length.
  • Midpoint (related, but separate): the point halfway between the endpoints, found by averaging coordinates: \(\left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right)\). It gives a location, not a length, though it splits the segment into two equal halves.

FAQ

Does the order of the points matter? No. Swapping the two endpoints flips the signs of \(\Delta x\) and \(\Delta y\), but squaring them produces the same length.

What units does the result use? The result is in the same units as your coordinates. If the axes are in centimeters, the length is in centimeters.

Can I use negative coordinates? Yes. The subtraction handles negative values correctly, for example from (−2, −1) to (2, 2).

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators