Distance Between Two Lines: Formula and Examples

#Geometry
TL;DR
The distance between two lines is the length of the shortest segment joining them, measured perpendicular to both. For parallel lines ax+by+c1=0ax + by + c_1 = 0 and ax+by+c2=0ax + by + c_2 = 0 it is d=∣c2−c1∣a2+b2d = \dfrac{|c_2 - c_1|}{\sqrt{a^2 + b^2}}; for skew lines in 3D it uses the cross product. This article defines both cases and works through examples.
MV
Madhukar VLast updated on July 22, 20269 min read

Why "The Distance Between Two Lines" Is Only One Number When The Lines Never Meet

Ask for the distance between two lines and the first surprise is that the answer only makes sense in special cases. If two lines cross, the distance is zero - they touch. If they run parallel, there is one fixed gap. And in three dimensions two lines can miss each other entirely without being parallel, leaving a single shortest bridge between them. Getting the right number means first knowing which case you are in.

The distance between two lines is the length of the shortest segment connecting them, and it is always measured perpendicular to both lines. Two lines fall into three cases: intersecting (distance 00), parallel (a constant perpendicular gap), and - in 3D only - skew (non-parallel lines that never meet, joined by a unique common perpendicular). This builds directly on the distance of a point from a line; for the plane it lives in, see coordinate geometry.

By the end you will identify the case, apply the right formula, and compute the distance for parallel lines in the plane and skew lines in space.

The Parallel-Lines Formula (2D)

Two lines are parallel when they have the same slope and never meet. Their perpendicular distance is the same everywhere, so you can measure it at any convenient point.

Write both lines with identical aa and bb coefficients:

ax+by+c1=0andax+by+c2=0ax + by + c_1 = 0 \qquad\text{and}\qquad ax + by + c_2 = 0

Then the distance is:

d=∣c2−c1∣a2+b2d = \frac{|c_2 - c_1|}{\sqrt{a^2 + b^2}}

Here aa and bb are the shared coefficients of xx and yy, and c1,c2c_1, c_2 are the two constants. The absolute value keeps the distance positive regardless of order, and a2+b2\sqrt{a^2+b^2} normalises for the line's direction. If the lines are given in slope form y=mx+c1y = mx + c_1 and y=mx+c2y = mx + c_2, rewrite as mx−y+c1=0mx - y + c_1 = 0, giving:

d=∣c2−c1∣m2+1d = \frac{|c_2 - c_1|}{\sqrt{m^2 + 1}}

The formula only works once both lines share the same aa and bb. If one is written 2x+4y=52x + 4y = 5 and the other x+2y=1x + 2y = 1, scale the second to 2x+4y=22x + 4y = 2 first.

The Skew-Lines Formula (3D)

In three dimensions, two non-parallel lines that never intersect are skew. There is exactly one segment perpendicular to both - the common perpendicular - and its length is the distance.

Write the lines in vector form, with position vectors a1⃗,a2⃗\vec{a_1}, \vec{a_2} and direction vectors b1⃗,b2⃗\vec{b_1}, \vec{b_2}:

r1⃗=a1⃗+t,b1⃗r2⃗=a2⃗+s,b2⃗\vec{r_1} = \vec{a_1} + t,\vec{b_1} \qquad \vec{r_2} = \vec{a_2} + s,\vec{b_2}

Then:

d=∣,(a2⃗−a1⃗)⋅(b1⃗×b2⃗),∣∣b1⃗×b2⃗∣d = \frac{\left|,(\vec{a_2} - \vec{a_1}) \cdot (\vec{b_1} \times \vec{b_2}),\right|}{\left|\vec{b_1} \times \vec{b_2}\right|}

The cross product b1⃗×b2⃗\vec{b_1} \times \vec{b_2} is a vector perpendicular to both lines' directions; the dot product in the numerator projects the gap between the lines onto that common perpendicular. If b1⃗×b2⃗=0⃗\vec{b_1} \times \vec{b_2} = \vec{0}, the directions are parallel and you must use the parallel formula instead. These vector operations extend coordinate geometry into 3D; the companion point-to-line distance handles the single-point case.

Examples Of The Distance Between Two Lines

Six worked cases, from a clean parallel pair to a full skew-line computation.

Example 1

Find the distance between 3x+4y+7=03x + 4y + 7 = 0 and 3x+4y−5=03x + 4y - 5 = 0.

The coefficients a=3a = 3, b=4b = 4 match, so the lines are parallel. c1=7c_1 = 7, c2=−5c_2 = -5. d=∣c2−c1∣a2+b2=∣−5−7∣9+16d = \dfrac{|c_2 - c_1|}{\sqrt{a^2 + b^2}} = \dfrac{|-5 - 7|}{\sqrt{9 + 16}} d=1225=125=2.4d = \dfrac{12}{\sqrt{25}} = \dfrac{12}{5} = 2.4 units.

Example 2

Find the distance between 2x+4y=52x + 4y = 5 and x+2y=1x + 2y = 1.

Wrong path first: plug straight in with c1=5c_1 = 5, c2=1c_2 = 1, a=2a = 2, b=4b = 4, giving 420\dfrac{4}{\sqrt{20}}. That is wrong, because the two lines do not share the same aa and bb (2,42, 4 versus 1,21, 2). Scale the second line by 22: 2x+4y=22x + 4y = 2, so 2x+4y−2=02x + 4y - 2 = 0 and 2x+4y−5=02x + 4y - 5 = 0. Now a=2a = 2, b=4b = 4, c1=−5c_1 = -5, c2=−2c_2 = -2. d=∣−2−(−5)∣4+16=320=325≈0.671d = \dfrac{|-2 - (-5)|}{\sqrt{4 + 16}} = \dfrac{3}{\sqrt{20}} = \dfrac{3}{2\sqrt5} \approx 0.671 units. The lesson: match the coefficients before applying the formula.

Example 3

Find the distance between the parallel lines y=2x+3y = 2x + 3 and y=2x−4y = 2x - 4.

Rewrite both as 2x−y+c=02x - y + c = 0: 2x−y+3=02x - y + 3 = 0 and 2x−y−4=02x - y - 4 = 0. Now a=2a = 2, b=−1b = -1, c1=3c_1 = 3, c2=−4c_2 = -4. d=∣−4−3∣4+1=75=755≈3.13d = \dfrac{|-4 - 3|}{\sqrt{4 + 1}} = \dfrac{7}{\sqrt{5}} = \dfrac{7\sqrt5}{5} \approx 3.13 units.

Example 4

Two lines cross at the point (1,2)(1, 2). What is the distance between them?

If two lines intersect, they share at least one point. At that shared point the gap between the lines is zero. So the distance between two intersecting lines is 00. The perpendicular-distance formulas apply only to parallel or skew lines, never to intersecting ones.

Example 5

Find the distance between the skew lines r1⃗=(0,0,0)+t(1,0,0)\vec{r_1} = (0,0,0) + t(1,0,0) and r2⃗=(0,1,1)+s(0,1,0)\vec{r_2} = (0,1,1) + s(0,1,0).

Directions: b1⃗=(1,0,0)\vec{b_1} = (1,0,0), b2⃗=(0,1,0)\vec{b_2} = (0,1,0). Cross product: b1⃗×b2⃗=(0⋅0−0⋅1, 0⋅0−1⋅0, 1⋅1−0⋅0)=(0,0,1)\vec{b_1} \times \vec{b_2} = (0\cdot0 - 0\cdot1,\ 0\cdot0 - 1\cdot0,\ 1\cdot1 - 0\cdot0) = (0, 0, 1). Its magnitude: ∣b1⃗×b2⃗∣=1|\vec{b_1} \times \vec{b_2}| = 1. Gap vector: a2⃗−a1⃗=(0,1,1)\vec{a_2} - \vec{a_1} = (0,1,1). Numerator: (0,1,1)⋅(0,0,1)=1(0,1,1)\cdot(0,0,1) = 1. d=∣1∣1=1d = \dfrac{|1|}{1} = 1 unit.

Example 6

Are the lines with directions b1⃗=(1,2,3)\vec{b_1} = (1, 2, 3) and b2⃗=(2,4,6)\vec{b_2} = (2, 4, 6) skew?

Notice b2⃗=2,b1⃗\vec{b_2} = 2,\vec{b_1}, so the directions are parallel. Their cross product is 0⃗\vec{0}, so the skew formula cannot be used (its denominator would be zero). Parallel lines are never skew; use the parallel-distance approach with a point on each line instead. This check — computing the cross product first — tells you which formula applies.

Where the distance between lines earns its keep: "the shortest bridge that never touches"

The perpendicular distance between lines is not a textbook trick. It answers a concrete question that appears wherever two straight paths must be kept apart.

  • The defining idea. The distance is the shortest possible connection, and it is always perpendicular because any slanted connection is longer. That "shortest perpendicular bridge" is what a designer computes to guarantee clearance.

  • Real-world stakes. In road, rail, and pipeline design, engineers must verify that two straight routes at different heights - an overpass above a highway, a pipe crossing beneath another - keep a required minimum clearance. Those routes are often skew lines in 3D, and the common-perpendicular distance is exactly the clearance that must exceed a safety threshold. The same skew-line distance appears in robotics for collision avoidance and in molecular geometry for the closest approach of two bonds. The general principle sits under analytic geometry.

  • Where it goes next. The line-to-line distance generalises the point-to-line distance, and it extends further to distances involving planes. The common thread across all of them is the same: the shortest distance is measured along a perpendicular.

That is why the perpendicular is not optional decoration - it is the distance, and identifying it correctly is the whole task.

Common Mistakes With The Distance Between Two Lines

Mistake 1: Applying the parallel formula without matching the coefficients

Where it slips in: Lines written with different aa and bb multiples.

Don't do this: Use 2x+4y=52x + 4y = 5 and x+2y=1x + 2y = 1 directly, reading c1=5c_1 = 5, c2=1c_2 = 1.

The correct way: Scale one equation so both have identical aa and bb first (Example 2), then read c1,c2c_1, c_2. The rusher who plugs in the raw constants gets a distance off by the scale factor.

Mistake 2: Measuring a slanted gap instead of the perpendicular one

Where it slips in: Estimating the distance from a graph by eye.

Don't do this: Read the vertical or horizontal gap between the lines as "the distance."

The correct way: The distance is always the perpendicular segment, which is shorter than any slanted gap. Use the formula, not a diagonal ruler reading. The second-guesser who measures the vertical drop between two slanted lines overstates the true perpendicular distance.

Mistake 3: Using the skew formula on parallel lines

Where it slips in: 3D problems where the directions turn out to be multiples of each other.

The correct way: Compute b1⃗×b2⃗\vec{b_1} \times \vec{b_2} first. If it is 0⃗\vec{0}, the lines are parallel and the skew formula's denominator vanishes - switch to the parallel method (Example 6). If it is non-zero and the lines do not intersect, they are skew and the cross-product formula applies.

Conclusion

  • The distance between two lines is the shortest, always-perpendicular segment joining them.

  • Two lines are intersecting (distance 00), parallel (constant gap), or skew (3D only, a common perpendicular).

  • Parallel lines: d=∣c2−c1∣a2+b2d = \dfrac{|c_2 - c_1|}{\sqrt{a^2 + b^2}}, after matching the aa and bb coefficients.

  • Skew lines: d=∣(a2⃗−a1⃗)⋅(b1⃗×b2⃗)∣∣b1⃗×b2⃗∣d = \dfrac{|(\vec{a_2} - \vec{a_1}) \cdot (\vec{b_1} \times \vec{b_2})|}{|\vec{b_1} \times \vec{b_2}|}, using the cross product.

  • Always check the case first: a zero cross product means parallel, not skew.

To take line-distance problems further with a teacher, explore Bhanzu's geometry tutor, our high school math tutor sessions, or math tutoring online. To watch a trainer set up a skew-line distance in 3D live, you can book a free demo class.

A practical next step

Work through the exercises below. Identify the case (parallel or skew) before choosing the formula.

  1. Find the distance between 5x−12y+2=05x - 12y + 2 = 0 and 5x−12y−24=05x - 12y - 24 = 0. (Answer to Question 1: d=∣−24−2∣25+144=2613=2d = \dfrac{|-24 - 2|}{\sqrt{25 + 144}} = \dfrac{26}{13} = 2 units.)

  2. Find the distance between the skew lines r1⃗=(1,0,0)+t(1,1,0)\vec{r_1} = (1,0,0) + t(1,1,0) and r2⃗=(0,0,1)+s(1,−1,0)\vec{r_2} = (0,0,1) + s(1,-1,0). (Answer to Question 2: b1⃗×b2⃗=(0,0,−2)\vec{b_1}\times\vec{b_2} = (0,0,-2), gap (−1,0,1)(-1,0,1), numerator ∣−2∣=2|-2| = 2, denominator 22, so d=1d = 1 unit.)

Read More

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

What is the distance between two lines?
It is the length of the shortest segment joining them, always measured perpendicular to both. It is defined for parallel lines (a constant gap) and, in 3D, for skew lines (the common perpendicular).
What is the formula for the distance between two parallel lines?
For ax+by+c1=0ax + by + c_1 = 0 and ax+by+c2=0ax + by + c_2 = 0, the distance is d=∣c2−c1∣a2+b2d = \dfrac{|c_2 - c_1|}{\sqrt{a^2 + b^2}}, provided both lines share the same aa and bb.
What is the distance between two intersecting lines?
Zero. Intersecting lines share a point, so the shortest distance between them is 00. The perpendicular-distance formulas apply only to parallel or skew lines.
How do you find the distance between skew lines?
Use d=∣(a2⃗−a1⃗)⋅(b1⃗×b2⃗)∣∣b1⃗×b2⃗∣d = \dfrac{|(\vec{a_2} - \vec{a_1}) \cdot (\vec{b_1} \times \vec{b_2})|}{|\vec{b_1} \times \vec{b_2}|}, where the cross product gives the common perpendicular direction and the dot product projects the gap onto it.
Can two lines in a plane be skew?
No. Skew lines exist only in three or more dimensions. In a plane, two lines either intersect or are parallel.
✍️ Written By
Madhukar V
Madhukar V
Math Columnist & Analyst
I see mathematics as more than just numbers and formulas—it is a way of thinking, questioning, and understanding the world around us. I work at the intersection of mathematics, EdTech, technology, and AI-powered learning, I enjoy exploring how mathematical ideas can be made simple, meaningful, and relatable. Through my articles, I aim to present mathematics with curiosity and a practical perspective, helping readers see the beauty and relevance behind every concept in a Bhanzu way.
LinkedIn
Related Articles
Book a FREE Demo ClassBook Now →