How to Add Line of Best Fit in Excel

To add a line of best fit in Excel, select your two columns of data and go to Insert > Scatter. Click the chart, select the Chart Elements button (the plus sign), and check Trendline. Excel draws a straight line through your points. To show its equation, right-click the line, choose Format Trendline, and check Display Equation on chart.

Applies to: Excel for Microsoft 365, Excel 2024, 2021, 2019, and 2016 on Windows and Mac. Checked against Microsoft Support on October 10, 2026.

Step 1: Make a scatter chart

  1. Put your data in two columns, with the X values (such as hours studied) on the left and the Y values (such as test scores) on the right.
  2. Select both columns, including the headings.
  3. Go to Insert, select the Scatter chart button in the Charts group, and choose the first option, Scatter.

Use a scatter chart, not a line chart. A line chart treats the X values as evenly spaced labels, so the trendline and its equation come out wrong.

Step 2: Add the trendline

  • Click the chart, select the Chart Elements button that appears beside it, and check Trendline.
  • Or right-click any data point and select Add Trendline.
  • On a Mac, click the chart and go to Chart Design > Add Chart Element > Trendline > Linear.

Step 3: Show the equation and R-squared

  1. Right-click the trendline and select Format Trendline.
  2. At the bottom of the pane, check Display Equation on chart and Display R-squared value on chart.
  3. Drag the label to a clear spot on the chart.

The equation is written as y = mx + b, where m is the slope and b is where the line crosses the Y axis. R-squared runs from 0 to 1. The closer it is to 1, the better the line fits your data.

Example: reading the result

Say you track hours studied (X) against test scores (Y), and the chart shows y = 4.8x + 52 with R² = 0.86. That means each extra hour of study goes with about 4.8 more points, a student who studied zero hours would be predicted to score about 52, and the line explains 86% of the variation in scores. A good fit shows a pattern, but it doesn’t prove one thing causes the other.

Choose a different kind of line

In the Format Trendline pane, you can pick another type if your points curve:

  • Linear: a straight line. The default, and the right choice for most data.
  • Exponential: for values that grow or shrink faster and faster. Y values must all be positive.
  • Logarithmic: for values that rise quickly, then level off. X values must all be positive.
  • Polynomial: for curves with peaks or dips. Set the Order to 2 for one bend, 3 for two.
  • Power and Moving Average: for more specialized cases.

Compare R-squared values to see which type fits best, but don’t choose a complicated curve just because it scores slightly higher.

Extend the line to make a forecast

In Format Trendline, enter a number under Forecast > Forward to extend the line past your data. For example, if X is in months, enter 3 to see where the trend points three months ahead.

Get the numbers with formulas

If you need the slope and intercept in cells, use these formulas, where B2:B20 holds the Y values and A2:A20 holds the X values:

  • =SLOPE(B2:B20,A2:A20) gives the slope.
  • =INTERCEPT(B2:B20,A2:A20) gives the intercept.
  • =RSQ(B2:B20,A2:A20) gives R-squared.
  • =FORECAST.LINEAR(25,B2:B20,A2:A20) predicts the Y value when X is 25.

These match the numbers in the chart’s equation, and they update when your data changes.

Change how the line looks

In Format Trendline, select the Fill & Line icon (the paint bucket). You can change the line’s color, width, and dash type, which helps when you have several trendlines on one chart.

Remove a trendline

Click the trendline to select it and press Delete. Or click the chart, open Chart Elements, and uncheck Trendline.

If something goes wrong

  • Trendline is missing from the menu: Trendlines don’t work on pie, doughnut, radar, 3-D, or stacked charts. Change the chart type to scatter.
  • The equation looks wrong: Check that you used a scatter chart, and that the X values are in the first column you selected.
  • The equation shows too few decimal places: Right-click the equation, select Format Trendline Label, and set Number with more decimal places.
  • Exponential or Logarithmic is greyed out: Your data has zero or negative values, which those types can’t use.

Frequently asked questions

Is a trendline the same as a line of best fit?

Yes. Excel calls it a trendline. A linear trendline is the least-squares line of best fit.

Can I add a line of best fit to more than one series?

Yes. Add a trendline to each series separately. Each one gets its own equation. See how to add multiple data sets to a graph in Excel.

Can I make the line start at zero?

Yes. In Format Trendline, check Set Intercept and leave it at 0. Only do this if your data really should pass through zero.

Related: how to add an average line in Excel and how to run descriptive statistics in Excel.

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy