Linear regression calculator

Paste your x and y data to get the line of best fit, R², a test of the slope and predictions, with every step of the math.

  • Free, no sign-up
  • Step-by-step working
  • Runs in your browser
  1. 1 Copy and paste your data
  2. 2 Choose an option
  3. 3 Click “Calculate”
  4. 4 Read the result
How to use the Linear regression calculator: 1. Copy and paste your data (copy the cells in Excel or Google Sheets, then paste them into the box). 2. Choose an option (95%). 3. Click “Calculate”. 4. Read the result (Line of best fit: ŷ = 46.86 + 4.48x).

Tip: No need to type: copy your numbers from Excel, Google Sheets or a CSV file and paste them straight into the box.

This is example data so you can see how the tool works. Replace it with your own: copy your numbers from Excel or Google Sheets and paste them in, or type them.

Step 1: Paste or type your data

Paste two columns from Excel or Google Sheets into either box and they're split for you, or separate values with commas, spaces or new lines.

Step 2: Predict and label (optional)

Step 3: Your regression line

How to use the linear regression calculator

  1. Copy your two columns from Excel or Google Sheets and paste them into the X box: they split into X and Y automatically. You can also type the values, one pair per position.
  2. Optionally enter an x value to predict y at, and name the variables so the chart and explanation use them.
  3. Click Calculate regression.
  4. Read the equation of the line, R² and the slope test, then check the chart and the residuals for curves or outliers.
  5. Download the chart as a PNG, or copy a link to these results to share them.

Linear regression formula

Simple linear regression fits the straight line that makes the squared vertical distances from the points to the line as small as possible (least squares):

y = b0 + b1x , b1 = SxySxx , b0 = y − b1x

How well the line fits, and whether the slope could really be zero:

R2 = 1 − SSESyy , s = SSEn − 2 , t = b1s / Sxx

y
The predicted value of y for a given x
b1
The slope: how much y changes, on average, for each one-unit increase in x
b0
The intercept: the predicted y when x = 0
Sxy, Sxx, Syy
Sums of cross-products and squared deviations: Σ(x − x)(y − y), Σ(x − x)2 and Σ(y − y)2
SSE
The sum of squared errors (residuals): Σ(y − y)2
R2
The coefficient of determination: the share of the variation in y the line explains
s
The standard error of the regression: the typical distance of a point from the line, in y units
t
The test statistic for the slope, with n − 2 degrees of freedom

Worked example

Five students report hours of sleep (x) and a quiz score out of 5 (y): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). Find the regression line.

  1. Find the means
    x = 3, y = 4
  2. Sum the cross-products and squared deviations of x
    Sxy = 6, Sxx = 10, Syy = 6
  3. Slope and intercept
    b1 = 610 = 0.6, b0 = 4 − 0.6 × 3 = 2.2
  4. The line
    y = 2.2 + 0.6x
  5. Fit: SSE = 6 − 0.6 × 6 = 2.4
    R2 = 1 − 2.46 = 0.60, s = 2.43 = 0.8944
  6. Test the slope with 5 − 2 = 3 degrees of freedom
    t = 0.60.8944 / 10 = 2.1213, p = 0.1240

What it means: each extra hour of sleep goes with a quiz score about 0.6 points higher, and the line explains 60% of the variation in scores. With only five students, though, p = 0.124 is above 0.05, so the slope isn't statistically significant: a sample this small can't rule out that the true slope is zero.

How to interpret the results

  • The equation is your model. Plug in an x value to predict y, but only within the range of x you measured.
  • The slope is the practical result: the change in y per unit of x. Its confidence interval shows how precisely you've pinned it down.
  • R² is the share of the variation in y the line explains. It says nothing about whether a straight line is the right shape.
  • The p-value for the slope tests whether there's any linear relationship at all. A tiny p-value with a small R² means a real but weak relationship.
  • The residuals (actual minus predicted) should look like random scatter. A curve or a funnel shape means a straight line isn't the whole story.

Working with lab standards? The standard curve calculator fits the same line and reads the concentration of your unknown samples off it. For just the strength of the relationship, use the correlation coefficient calculator.

Frequently asked questions

What is the difference between correlation and linear regression?

Correlation gives one number, r, for how strongly two variables move together, and it treats them the same way round. Regression fits an actual line, ŷ = b₀ + b₁x, so you can predict y from x; swapping x and y gives a different line. In simple linear regression, R² is the square of r, and the slope test gives exactly the same p-value as the correlation test.

What is a good R² value?

It depends on the field. In physics, chemistry or a lab calibration curve, you would expect R² above 0.99. In biology, economics or the social sciences, where many things affect the outcome, R² of 0.3 to 0.5 can be a useful model. A high R² doesn’t prove the line is the right model either: always look at the scatter plot and residuals for curves or outliers.

How do I interpret the slope and intercept?

The slope b₁ is the change in y for each one-unit increase in x: a slope of 4.5 means y goes up by 4.5 on average for every extra unit of x. The intercept b₀ is the predicted y when x = 0. That is only meaningful if x = 0 is realistic and within your data; otherwise treat it as the point where the line crosses the axis, nothing more.

What is the difference between a confidence interval and a prediction interval?

The confidence interval is for the average y of all items with that x value, so it is fairly narrow. The prediction interval is for one new item with that x value, so it also includes the item’s own scatter around the line and is always wider. Use the prediction interval when you are forecasting a single case.

Can I predict outside the range of my data?

You can calculate it, but be careful. That is extrapolation: the straight-line pattern may not continue beyond the x values you measured. Prices, growth and dose responses often level off or curve. The calculator warns you when the x value you predict at is outside your data.

How do I do linear regression in Excel or Google Sheets?

Use =SLOPE(B2:B20, A2:A20) and =INTERCEPT(B2:B20, A2:A20) for the line (y range first), =RSQ(B2:B20, A2:A20) for R² and =FORECAST.LINEAR(x, B2:B20, A2:A20) to predict. =LINEST(B2:B20, A2:A20, TRUE, TRUE) returns the standard errors too. This calculator gives the same numbers plus the tests, intervals and working.

Last reviewed November 12, 2026