ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Math
  3. How to Do Linear Regression in Excel: SLOPE to LINEST

How to Do Linear Regression in Excel: SLOPE to LINEST

By ExcelReady Team·Updated November 3, 2026·7 min read

The short answer

For a simple linear regression in Excel, use =SLOPE(known_y, known_x) for the slope, =INTERCEPT(known_y, known_x) for where the line starts, and =RSQ(known_y, known_x) for how well it fits. Predict new values with FORECAST.LINEAR. For full statistics use LINEST or the Analysis ToolPak, and to see the line, add a trendline to a scatter chart.

Key takeaways

  • Linear regression fits the straight line y = intercept + slope × x that best matches your data.
  • SLOPE, INTERCEPT and RSQ all take the y values first, then the x values.
  • FORECAST.LINEAR predicts y for a new x; TREND does the same for many x values at once.
  • LINEST returns the slope, intercept and, with its 4th argument TRUE, standard errors and R² in one array.
  • A good fit is not proof of cause, and predictions far outside your data range are guesses.
On this page+
  1. What does linear regression tell you?
  2. Quick method: SLOPE, INTERCEPT and RSQ
  3. How to predict a value with FORECAST.LINEAR and TREND
  4. How to use LINEST for the full regression
  5. Add a trendline to a scatter chart
  6. Run a regression with the Analysis ToolPak
  7. How Excel calculates the slope
  8. Common linear regression mistakes
  9. Practise it

Linear regression in Excel finds the straight line that best fits two columns of numbers, so you can see how much one changes when the other does and predict new values. Excel gives you four ways to do it: quick functions (SLOPE, INTERCEPT, RSQ), the all-in-one LINEST, a chart trendline and the Analysis ToolPak. This guide is for students, analysts and job seekers who need a regression without a statistics package, and it uses one small data set throughout.

What does linear regression tell you?#

A simple linear regression fits the line y = intercept + slope × x through your data. Here, x is the input you know and y is the result you want to explain or predict.

The example is six deliveries, with the distance in km and the delivery time in minutes:

ABC
1DeliveryKmMinutes
2D1215
3D2317
4D3521
5D4625
6D5829
7D61035

The regression answers three questions:

  • Slope: how many extra minutes each extra km adds.
  • Intercept: the predicted time at 0 km, which you can think of as fixed handling time.
  • R² (R squared): how well the line fits, from 0 (no fit) to 1 (every point on the line).

Quick method: SLOPE, INTERCEPT and RSQ#

Three functions give you the line and its fit. All three take the y values first, then the x values:

Excel formula
=SLOPE(C2:C7,B2:B7)
=INTERCEPT(C2:C7,B2:B7)
=RSQ(C2:C7,B2:B7)
FunctionResultMeaning
SLOPE2.5Each extra km adds 2.5 minutes
INTERCEPT9.5About 9.5 minutes at 0 km
RSQ0.993The line explains 99.3% of the variation in time

So the fitted line is Minutes = 9.5 + 2.5 × Km. RSQ is the square of the correlation coefficient; the guide to finding the correlation between two columns explains that number. These functions work in every current version of Excel.

How to predict a value with FORECAST.LINEAR and TREND#

To predict y for a new x, use FORECAST.LINEAR. With 12 km in E2:

Excel formula
=FORECAST.LINEAR(E2,C2:C7,B2:B7)

The result is 39.5 minutes (9.5 + 2.5 × 12). The new x comes first, then the known y values, then the known x values. FORECAST.LINEAR was added in Excel 2016; older files use FORECAST, which gives the same answer.

TREND does the same for many new x values at once. In Microsoft 365 and Excel 2021, =TREND(C2:C7,B2:B7,E2:E4) spills one prediction per value in E2:E4. You can also write the line yourself, =$H$2+$H$1*E2 with the slope in H1 and the intercept in H2, and fill it down. The $ signs keep the slope and intercept fixed while E2 moves.

How to use LINEST for the full regression#

LINEST returns the whole regression in one array. Its syntax is:

Excel formula
=LINEST(known_y's, [known_x's], [const], [stats])

=LINEST(C2:C7,B2:B7) returns two cells side by side: 2.5 and 9.5, the slope then the intercept. Set the 4th argument to TRUE to add statistics:

Excel formula
=LINEST(C2:C7,B2:B7,TRUE,TRUE)

This returns 5 rows by 2 columns. Row 1 is the slope and intercept, row 2 their standard errors, and row 3 holds R² (0.993) and the standard error of the estimate (about 0.71 minutes). Rows 4 and 5 hold the F statistic, degrees of freedom and sums of squares.

In Microsoft 365 and Excel 2021, LINEST spills into the cells beside and below it, so leave them empty to avoid a #SPILL! error. In older versions, select a 5 × 2 range first, type the formula and press Ctrl+Shift+Enter (Mac: ⌘+Shift+Return). For more than one input, such as distance and number of stops, give LINEST an x range of two or more side-by-side columns. The slopes then come back in reverse column order.

Add a trendline to a scatter chart#

A chart shows whether a straight line makes sense at all. Select B1:C7, choose Insert > Scatter, then:

  1. Click a data point and choose Add Trendline (right-click on Windows; Control-click on a Mac).
  2. Pick Linear.
  3. Tick Display Equation on chart and Display R-squared value on chart.

The chart shows y = 2.5x + 9.5 and an R² of about 0.993, the same as the functions. Use a scatter chart, not a line chart, because a line chart treats x as evenly spaced labels. The guide to line charts in Excel explains when each fits, and scatter plots in Excel covers trendline options.

Run a regression with the Analysis ToolPak#

The Analysis ToolPak writes a full regression report with one dialog. Turn it on under File > Options > Add-ins, choose Excel Add-ins and click Go (on a Mac: Tools > Excel Add-ins), then tick Analysis ToolPak.

Then choose Data > Data Analysis > Regression, set Input Y Range to C1:C7 and Input X Range to B1:B7, tick Labels and pick an output cell. The report includes R², the coefficients, their standard errors, t statistics and p-values, and optional residuals. The output is fixed values, not formulas, so run it again if the data changes.

How Excel calculates the slope#

The slope is the sum of (x gap × y gap) divided by the sum of (x gap squared), where each gap is the distance from that column's average. With the gaps in D2:D7 and E2:E7 (=B2-AVERAGE($B$2:$B$7) and =C2-AVERAGE($C$2:$C$7)):

Excel formula
=SUMPRODUCT(D2:D7,E2:E7)/SUMPRODUCT(D2:D7,D2:D7)

The top is about 113.33 and the bottom about 45.33, so the slope is 2.5. The intercept is then the average time minus the slope times the average distance: 23.67 − 2.5 × 5.67, which is 9.5 before rounding. Building it by hand like this is a good check when a result looks odd. The guides to SUMPRODUCT in Excel and the AVERAGE function cover the two building blocks, and standard deviation in Excel uses the same gaps from the average.

Common linear regression mistakes#

Check these before you trust a regression:

  1. x and y swapped. SLOPE, INTERCEPT, RSQ and FORECAST.LINEAR all want y before x. Swapping them gives a different line.
  2. Predicting far outside the data. The data runs from 2 to 10 km. A prediction for 50 km assumes the pattern holds that far, which it may not.
  3. Fitting a line to a curve. A high R² on a curved pattern can still mislead. Look at the scatter chart first.
  4. Reading cause into a fit. Two columns can move together because of a third factor. Regression measures the pattern, not the reason.
  5. Ranges of different sizes or with text. Keep x and y the same length and remove text and blanks from the rows you use.

For trends over time rather than between two measures, a moving average is often the simpler tool.

Practise it#

Regression rests on averages and on references that stay fixed when you fill a formula down. Practise AVERAGE, MIN and MAX in a live spreadsheet: you type the formula and it checks it instantly. Then practise relative and absolute references, the $ skill behind the gap columns in the exercise on this page.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

This practice sheet has no SLOPE function, so calculate the slope the way Excel does. Columns D and E hold each delivery's distance from the average distance and from the average time. In B9, divide SUMPRODUCT(D2:D7,E2:E7) by SUMPRODUCT(D2:D7,D2:D7), then press Enter.

fx
ABCDEF
1
Delivery
Km
Minutes
Km gap
Minutes gap
2
D1
2
15
-3.666666667
-8.666666667
3
D2
3
17
-2.666666667
-6.666666667
4
D3
5
21
-0.6666666667
-2.666666667
5
D4
6
25
0.3333333333
1.333333333
6
D5
8
29
2.333333333
5.333333333
7
D6
10
35
4.333333333
11.33333333
8
9
Slope
10
11
12

Tip: =SUMPRODUCT(D2:D7,E2:E7)/SUMPRODUCT(D2:D7,D2:D7). The top is about 113.33 and the bottom about 45.33, so the slope is 2.5 minutes per km.

Practise this in a lesson

LessonAVERAGE, MIN and MAXSummarize a list with its average, smallest and largest values.LessonRelative vs absolute references ($)Lock a cell with $ so it doesn't move when you copy a formula, one of the most-tested Excel skills.Function guideAVERAGECalculate the mean in Excel with AVERAGE. See how it treats blanks and zeros, avoid common errors, and practice in a live sheet.

Frequently asked questions

How do I do a linear regression in Excel?

+

For one input, use =SLOPE(y range, x range) and =INTERCEPT(y range, x range) to get the line, and =RSQ(y range, x range) for the fit. For more detail or several inputs, use LINEST or Data > Data Analysis > Regression from the Analysis ToolPak.

What is the difference between SLOPE and LINEST?

+

SLOPE returns one number, the slope. LINEST returns an array: the slope and intercept, and with its stats argument set to TRUE, also standard errors, R squared and other regression statistics. LINEST can also handle several x columns.

How do I add a regression line to a chart in Excel?

+

Make a scatter chart of the two columns, click a data point, choose Add Trendline, pick Linear, and tick Display Equation on chart and Display R-squared value on chart.

What does R squared mean in Excel regression?

+

R squared is the share of the variation in y that the line explains, from 0 to 1. A value of 0.99 means the points sit very close to the line; a value near 0 means the line explains almost nothing.

What is the difference between FORECAST and FORECAST.LINEAR?

+

They give the same result. FORECAST.LINEAR is the newer name, added in Excel 2016. FORECAST still works for compatibility with older files.

Sources

  • SUMPRODUCT function - Microsoft Support
  • AVERAGE function - Microsoft Support
  • Dynamic array formulas and spilled array behavior - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What does linear regression tell you?
  2. Quick method: SLOPE, INTERCEPT and RSQ
  3. How to predict a value with FORECAST.LINEAR and TREND
  4. How to use LINEST for the full regression
  5. Add a trendline to a scatter chart
  6. Run a regression with the Analysis ToolPak
  7. How Excel calculates the slope
  8. Common linear regression mistakes
  9. Practise it

Keep reading

Math· 6 min read

How to Calculate a Moving Average in Excel

To calculate a 3-period moving average in Excel, put =AVERAGE(B2:B4) next to the third value and fill it down. Because the references are relative, each row averages its own value and the two before it, so the window moves one row at a time. Don't add $ signs, or the window stops moving and becomes a cumulative average.

Math· 7 min read

How to Calculate Standard Deviation in Excel

To calculate standard deviation in Excel, use =STDEV.S(B2:B7) when your data is a sample, or =STDEV.P(B2:B7) when it covers the whole group you care about. Standard deviation measures how far values typically sit from the average. A small result means the values are close together; a large one means they are spread out.

Math· 6 min read

SUMPRODUCT in Excel: Multiply and Add in One Step

SUMPRODUCT multiplies matching items in two or more ranges and adds up the results. =SUMPRODUCT(C2:C7,D2:D7) multiplies each quantity by its price and returns the total, with no helper column. It also handles conditions, such as =SUMPRODUCT((B2:B7="North")*C2:C7*D2:D7), and works in every version of Excel.

More on math

  • Markup Formula in Excel and How It Differs From Margin
  • MEDIAN and MODE in Excel: Find the Typical Value
  • MOD and INT in Excel: Remainders and Whole Numbers
  • Turn Negative Numbers Into Zero in Excel
  • Normal Distribution in Excel: NORM.DIST and a Bell Curve
  • How to Normalize Data in Excel: Min-Max Scaling 0 to 1
All math articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free