Slope calculator: slope and equation of a line from two points

Find the slope as an exact fraction, plus the line equation, intercepts, angle, distance, midpoint and a graph. Runs on your device.

How it works

  1. Type the x and y values of the two points
  2. Read the slope, the line in three forms, the angle and the distance
  3. Check the graph and the working box

How the slope between two points is worked out

The slope between two points is the rise divided by the run, m = (y₂ − y₁) ÷ (x₂ − x₁). The page opens with the points (−1, 2) and (3, 8): the rise is 8 − 2 = 6, the run is 3 − (−1) = 4, and m = 6 ÷ 4 = 3/2 = 1.5. Slopes are kept as exact fractions, so 1/3 is shown as 1/3 with its decimal 0.3333 beside it, never as a rounded guess. A positive slope rises from left to right and a negative slope falls. Coordinates may have up to 4 decimals and be as large as 1,000,000 in size.

The equation of the line in three forms

The y-intercept is b = y₁ − m × x₁ = 2 − 1.5 × (−1) = 3.5, which gives slope-intercept form y = (3/2)x + 7/2. Point-slope form uses the first point: y − 2 = (3/2)(x + 1). Standard form Ax + By = C uses whole numbers, found by clearing the fractions: multiplying by 2 gives 3x − 2y = −7, with A not negative and no common factor left. A decimal version, y = 1.5x + 3.5, is shown too when the fractions are not whole numbers. The x-intercept is where the line crosses the x-axis: here x = −7/3.

Vertical and horizontal lines

If both points have the same x, the run is 0 and dividing by 0 is undefined, so the line is vertical, its slope is undefined and its equation is x = a number, for example x = 4. A vertical line has no y-intercept unless it is the y-axis itself. If both points have the same y, the rise is 0, the slope is 0 and the line is horizontal, y = a number, with no x-intercept unless it is the x-axis. Two identical points do not define a line, and the page says so instead of showing a result.

Angle, distance, midpoint and the graph

The angle of inclination is θ = tan⁻¹(m), measured from the positive x-axis between 0° and 180°, so a slope of 3/2 gives 56.3099° and a falling line gives an angle above 90°. The distance between the points is √(run² + rise²) = √(16 + 36) = √52 = 2√13, about 7.2111; the exact radical is shown when the squared distance is a whole number. The midpoint is the average of the coordinates, here (1, 5). The graph draws the line and both points with the same unit length on both axes, so the picture shows the true steepness. This page handles straight lines only, not curves.

Frequently asked questions

How do I find the slope between two points?

Subtract the y values and divide by the difference of the x values: m = (y₂ − y₁) ÷ (x₂ − x₁). For (1, 2) and (4, 8) that is 6 ÷ 3 = 2. Swapping the two points gives the same slope.

What is the slope of a vertical line?

It is undefined. A vertical line has the same x everywhere, so the run is 0 and the division by zero has no value. For the points (4, 1) and (4, 9) the page shows the slope as undefined and the equation as x = 4.

How do I write the equation of a line through two points?

Find the slope m, then the intercept b = y₁ − m × x₁, and write y = mx + b. For (−1, 2) and (3, 8), m = 3/2 and b = 7/2, so y = (3/2)x + 7/2, or 3x − 2y = −7 in standard form.

What does a negative slope mean?

The line falls as x grows. For (0, 5) and (2, 1) the rise is −4 and the run is 2, so m = −2: every step of 1 to the right drops the line by 2. The angle with the x-axis is then above 90°, 116.5651° in this case.

How do I turn a slope into an angle?

Take the inverse tangent of the slope: θ = tan⁻¹(m). A slope of 1 is 45°, a slope of 2 is 63.4349°, and a slope of 0 is 0°. The page measures from the positive x-axis, from 0° up to 180°.

Are my numbers stored or sent anywhere?

No. The numbers are processed in your browser and are not uploaded. They are not stored on your device either, and reloading the page puts the example points back.