All Tools490+

Linear Regression Calculator – Line of Best Fit in 2 Easy Steps

Linear Regression Calculator - VectraTools

Linear Regression Calculator

Free linear regression calculator – find the line of best fit (Y = mX + b) by entering your independent (X) and dependent (Y) variables.

Variable X (Independent)

Enter values separated by commas or new lines.

Variable Y (Dependent)

Must have the exact same number of values as X.

Regression Analysis Report
Line of Best Fit Equation
Y = 0X + 0
Slope (m)
0.0000
Y-Intercept (b)
0.0000
R-Squared (R²)
0.0000

Use this free linear regression calculator to find the line of best fit for your data in seconds.

Quick answer

Simple linear regression fits Y = mX + b with slope m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and intercept b = ȳ − m·x̄. Example: X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5 give Y = 0.6X + 2.2 with R² = 0.6, meaning 60% of the variation in Y is explained by X. This linear regression calculator shows the equation, slope, intercept and R².

Linear regression is the simplest way to describe how one variable changes with another: how sales rise with ad spend, how exam scores relate to study hours, or how temperature affects energy use. The result is a straight line that best fits your points.

Our free linear regression calculator uses the least-squares method. Paste your X and Y values (comma or line separated), click calculate and get the equation of the line, the slope, the y-intercept and R².

Linear Regression Formulas

ValueFormula
Slope (m)Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
Intercept (b)ȳ − m·x̄
Line of best fitŶ = mX + b
R² (coefficient of determination)1 − SSres ÷ SStot

Worked Example

  1. Means: x̄ = 3, ȳ = 4.
  2. Σ(x − x̄)(y − ȳ) = (−2)(−2) + (−1)(0) + 0 + (1)(0) + (2)(1) = 6.
  3. Σ(x − x̄)² = 4 + 1 + 0 + 1 + 4 = 10.
  4. Slope m = 6 ÷ 10 = 0.6; intercept b = 4 − 0.6·3 = 2.2.
  5. Equation: Y = 0.6X + 2.2, R² = 0.6.

How to read R²

  • R² = 1: all points lie on the line.
  • R² around 0.6: a moderate linear relationship.
  • R² near 0: the line explains almost none of the variation.

How to Use the Linear Regression Calculator

Get your regression line in two steps.

Step 1: Enter Your X and Y Values

Paste the independent values into Variable X and the dependent values into Variable Y, separated by commas or new lines. Both lists must have the same number of values. Click Calculate Equation.

Step 1 enter X and Y values in the linear regression calculator

Step 2: Read the Regression Report

The Regression Analysis Report shows the line of best fit equation, the slope, the y-intercept and R². Use Share or Download to save the results.

Step 2 linear regression line of best fit Y = 0.6X + 2.2 with R squared 0.6

Using the Equation to Predict

Once you have Y = 0.6X + 2.2, plug in a new X to predict Y. For X = 6, Ŷ = 0.6·6 + 2.2 = 5.8. Be careful predicting far outside your data range – the relationship may not stay linear.

Assumptions to Keep in Mind

  • The relationship should look roughly linear on a scatter plot.
  • Residuals (errors) should be random, without a pattern.
  • Outliers can pull the line strongly – check them before trusting the result.
  • Correlation is not causation: a good fit does not prove X causes Y.

Check the strength of the relationship with the Pearson Correlation Calculator, or for ranked data use the Spearman’s Rank Correlation Calculator.

Frequently Asked Questions

What does a linear regression calculator do?

It finds the straight line Y = mX + b that best fits your data using least squares, plus the slope, intercept and R².

What is R² in linear regression?

R² is the share of the variation in Y explained by X, from 0 to 1. Higher means a better fit.

How many data points do I need?

At least two, but use as many as you can – more points give a more reliable line.

Can I paste data from Excel?

Yes. Copy a column and paste it; values on new lines are accepted.

What is the difference between regression and correlation?

Correlation measures the strength of a relationship; regression gives the equation to predict Y from X.

Is the linear regression calculator free?

Yes. It is free, runs in your browser and needs no sign-up.

MH

Written and tested by Muhammad Hasnain

Founder of VectraTools. Behaviour described here was checked against the tool’s own output. Last reviewed: October 2026.