You find the line of best fit from a scatter plot by fitting a straight line that minimizes the total squared vertical distance between the points and the line, then reading its slope and intercept off the result. On paper, that means drawing a line with roughly equal counts of points above and below it and equal spread on both sides; in a spreadsheet it means running a linear trendline. The condition that matters most: only do this when the cloud of points looks roughly straight, because a line fit to curved data will mislead you no matter how carefully it's drawn.
A scatter plot shows paired measurements as dots β one variable on the horizontal axis, the other on the vertical. The line of best fit, also called the least-squares regression line, is the single straight line that comes closest to all of them at once. Its slope tells you how much the vertical variable tends to change for each one-unit increase in the horizontal variable. Its intercept tells you the predicted vertical value when the horizontal value is zero, which is often a mathematical artifact rather than a meaningful quantity.
The reason "closest" needs a definition is that a line can be close to some points and far from others. Statisticians settle the disagreement by squaring every vertical gap and adding them up, which is why the method is called ordinary least squares. Squaring does two things: it treats misses above and below the line identically, and it punishes large misses far more than small ones, so one wild outlier pulls the line harder than five tight points. Keep that sensitivity in mind, because it drives most of the mistakes people make with trendlines.
Three routes cover almost every real situation. If you have a spreadsheet, the built-in trendline and its R-squared statistic take about thirty seconds. If you're working by hand for a class or a quick sketch, the eyeball-and-adjust method gets you within a reasonable margin. If you want the exact equation, the slope and intercept formulas give it to you in two calculations. Each route below is spelled out with the on-screen names and the failure cases that trip people up.
Count Your Points and Label Both Axes Before You Fit Anything
If your axes aren't labeled with units, stop and label them, because the slope you're about to compute is meaningless without them. A slope of 2.5 means something completely different for kilograms versus pounds on the vertical axis. The horizontal and vertical variables also swap roles depending on which one you treat as explanatory and which as the outcome, and reversing them changes the slope to its reciprocal β a detail most quick tutorials skip. Decide which variable drives the other before you draw a single line.
Check how many points you actually have. A line fit to four points is a sketch; a line fit to forty is a summary. There's no universal minimum, but the smaller the sample, the more one unusual measurement dominates the result. Count your points, note any that sit far from the main cluster, and decide in advance whether each has a legitimate reason to be there. A data-entry error and a genuine extreme reading look identical on the plot but deserve opposite treatment.
Label the horizontal axis as the explanatory variable and the vertical axis as the response, with units on both. In spreadsheets this usually means putting your x-values in one column and y-values in the next, with headers, so the chart tool picks them up automatically. If your software plots the first column on the horizontal axis by default, verify it did so rather than assuming. Swapped axes produce a technically valid line that answers the wrong question.
Finally, look at the shape of the cloud before committing to a straight line. Points falling along a gentle curve, a U-shape, or a fan that widens to one side are all signals that a straight line is the wrong tool. For a fan shape β spread increasing as x grows β the slope estimate is still usable but the uncertainty around it isn't constant, and prediction intervals from ordinary least squares will be too narrow at the wide end. Note the shape in one sentence before you fit.
Eyeball the Line, Then Adjust It With the Equal-Counts Rule
The hand method starts with a line through the middle of the cloud, positioned so roughly the same number of points sit above it as below. Don't aim for the geometric center of the dots; aim for balance. Then check the spread: the distances from the points above the line should look similar in size to the distances from the points below. If the line passes through the cluster but hugs the top points tightly while leaving the bottom points far away, slide it down slightly and re-check both counts and gaps.
Pivot the line around a point near the middle of the data until the gaps on both sides look even. A useful physical trick: hold a ruler on the plot along a candidate line and tilt it until the sum of vertical gaps above roughly equals the sum below, weighted by how far each point sits from the center. Points near the ends have more leverage on the tilt than points in the middle, so a single distant point at the far right will swing the line more than you expect. Re-check after every adjustment.
Anchoring the line at two well-separated points makes the result reproducible. Pick a point near the left end of the data range and one near the right end, both sitting close to the center of the vertical spread at that horizontal position, and draw through them. This is where the anchor-point check earns its keep: if you repeat the exercise tomorrow and land on nearly the same two anchors, your line is stable. If your anchors jump around, the cloud is too noisy for hand-fitting and you should go to the formulas.
The equal-counts rule is a sanity check, not a guarantee. A line can split the points evenly and still be tilted wrong, because counts ignore distance. That's exactly the gap least squares fills. Use the eyeball method to understand the data and to catch gross errors β a hand line that disagrees wildly with a spreadsheet trendline usually means a mislabeled column or a stray point. Use the computed line whenever the number matters.
In Google Sheets, Two Menu Paths Get You the Trendline and Its Equation
Google Sheets gives you a trendline in two ways, and the menu names differ slightly depending on how the chart was created. Select your two columns including headers, then choose Insert > Chart. In the Chart editor panel on the right, open the Customize tab, open the Series section, and switch Trendline to On. Below that, Label becomes available; choose Use Equation to display the slope-and-intercept form directly on the chart, and choose Show R-squared to display the coefficient of determination. The equation appears as y = m x + b with your numbers filled in.
The second path suits scatter charts specifically. With a scatter chart selected, the same Customize > Series > Trendline controls apply, but Google Sheets also offers a Trendline type dropdown with Linear, Exponential, Polynomial, Logarithmic, and Moving average options. Leave it on Linear for a straight line. If your chart type is Line chart rather than Scatter, the trendline treats your horizontal values as categories, which produces a visually plausible line with a wrong slope. Confirm the chart type reads Scatter before trusting the output.
Failure case worth knowing: if your x-column contains text, dates stored as text, or blank cells mixed in, Sheets may plot points at odd positions or drop them silently. Check the point count on the chart against your row count. A second common failure is selecting only part of a column, so the chart covers the visible rows and ignores the rest. The chart doesn't warn you. Compare the number of dots to the number of data rows every time.
For a quick exact calculation without a chart, type =SLOPE(B2:B21, A2:A21) for the slope and =INTERCEPT(B2:B21, A2:A21) for the intercept, assuming y-values in column B and x-values in column A. Add =RSQ(B2:B21, A2:A21) for R-squared. These functions return numbers you can round and report, and they update when the data changes. Note the argument order: SLOPE takes the y-range first. Reversing the ranges gives the reciprocal slope, which is the single most common spreadsheet error in regression work.
Excel Calls It a Trendline and Adds the Display Equation Option
In Excel, select the two columns and insert a Scatter chart from the Insert tab's Charts group. Right-click any data point and choose Add Trendline. The Format Trendline pane opens on the right with Linear selected by default. Scroll to the bottom of the pane and tick Display Equation on chart and Display R-squared value on chart. Excel writes the equation in the form y = m x + b, using the same slope-intercept convention as Sheets, so the numbers transfer directly.
The pane also exposes Forecast Forward and Forecast Backward boxes, measured in axis units. Extending the line a short distance beyond your data is legitimate for showing a trend; extending it far beyond is prediction, and it deserves a caveat in whatever you present. Excel's trendline has no built-in warning when the fit is poor, so read the R-squared and judge it in context rather than treating the equation as gospel. A low R-squared with a steep slope can still be useful for direction, but not for pinning down a value.
For cell-level control, Excel's =LINEST function returns both the slope and the intercept in one formula, along with optional statistics. Enter =LINEST(B2:B21, A2:A21) as an array formula in modern Excel by typing it into one cell and confirming; the slope appears first and the intercept second. =SLOPE and =INTERCEPT work exactly as in Sheets. =RSQ gives the coefficient of determination. These are the same computations the trendline performs, so the values should match to rounding.
One version-specific difference is worth flagging. Older Excel releases and some web versions handle the LINEST array output differently, sometimes requiring a two-cell selection before entry. If the formula returns a single number rather than two, you've selected one cell instead of two. In Excel for the web, the Add Trendline dialog is available but the statistics options are reduced; for full control, use the desktop app or the SLOPE and INTERCEPT functions, which work identically everywhere.
Derive the Slope and Intercept Yourself With Two Formulas
If you need the exact least-squares line and have no spreadsheet handy, two formulas do the whole job. Compute the mean of x, written xΜ, and the mean of y, written Θ³. Then the slope m equals the sum of (x β xΜ)(y β Θ³) for every point, divided by the sum of (x β xΜ)Β² for every point. The intercept b equals Θ³ β mΒ·xΜ. That's the entire method: one ratio and one subtraction, which is why least squares fits on a single line of a calculator.
| Step | What to compute | Worked example (x, y pairs: (1,2), (2,4), (3,5), (4,4), (5,5)) |
|---|---|---|
| 1 | Mean of x | xΜ = (1+2+3+4+5)/5 = 3 |
| 2 | Mean of y | Θ³ = (2+4+5+4+5)/5 = 4 |
| 3 | Sum of (x β xΜ)(y β Θ³) | (β2)(β2) + (β1)(0) + (0)(1) + (1)(0) + (2)(1) = 4 + 0 + 0 + 0 + 2 = 6 |
| 4 | Sum of (x β xΜ)Β² | 4 + 1 + 0 + 1 + 4 = 10 |
| 5 | Slope m | 6 Γ· 10 = 0.6 |
| 6 | Intercept b | 4 β 0.6 Γ 3 = 2.2 |
| 7 | Final equation | y = 0.6x + 2.2 |
Check the arithmetic against the plot: the line rises six-tenths of a unit for every one unit right, and at x = 0 it sits at 2.2. Run the same numbers through a spreadsheet's SLOPE and INTERCEPT functions and you should get exactly these values, which makes this a good verification exercise. The formula is not an approximation; it returns the true least-squares line for any set of points with at least two distinct x-values.
The failure case here is arithmetic bookkeeping, not statistics. A single sign error in the deviation products flips the slope, so compute in a table with one row per point and a running sum column. Check that your squared deviations are all non-negative, since a negative value means a sign slipped. And verify the final line by plugging in the smallest and largest x-values and confirming the resulting y-values fall near the vertical spread of your data at those positions.
Curved data produces a perfectly good-looking slope from this formula and a badly wrong interpretation. The mathematical fit doesn't check whether a straight line is appropriate; that judgment is yours. Before trusting the output, plot the points and look. A tiny slope with a tight cluster near the mean can also emerge from data that has no real relationship, so pair the slope with a look at the spread.
Judge the Fit With R-Squared and the Spread of Residuals
R-squared, the coefficient of determination, runs from 0 to 1 and reports the fraction of the vertical variation explained by the line. An R-squared of 0.64 means 64% of the variation in y is accounted for by x. The remaining 36% is spread around the line and isn't explained by the linear relationship. Values near 1 indicate points sit tightly on the line; values near 0 indicate the line barely beats using the mean of y as a prediction for everything.
A single R-squared number doesn't tell you what counts as good. In physics labs, 0.95 can be disappointing; in social science data, 0.30 can be informative. Judge by the use. If you're predicting an individual value, you need a high R-squared plus an honest prediction interval. If you're describing a tendency across a population, a modest R-squared still supports the direction of the relationship. State the number alongside the slope so your reader can weigh it.
Residuals are the vertical gaps between each point and the line. Plot them mentally, or literally in a spare column, by subtracting the predicted y from the observed y for each point. In a well-behaved fit, residuals look randomly scattered with no pattern. A curved pattern in the residuals, or residuals that grow steadily larger as x increases, means the linear model is missing something. That check catches problems the R-squared hides.
The number of points also shapes how much R-squared you should trust. With few points, R-squared can be high by coincidence, and a single added point can swing it substantially. A rough rule of thumb: the more parameters you fit, the more data you need, and a straight line with two parameters is the least demanding case. Still, don't quote an R-squared from five points as if it were a property of the underlying process β it's a property of those five points.
Watch for Outliers, Curvature, and the Absolute Zero Trap
An outlier is a point far from the rest, and in least squares it has outsized influence because its squared gap enters the sum. Removing a legitimate outlier to improve the fit is data manipulation; investigating it to understand why it's there is analysis. Ask three questions: is it a measurement or entry error, does it belong to the population you're studying, and does the line change dramatically without it? If the slope flips sign when one point leaves, report that sensitivity rather than a clean equation.
Curvature is the second trap. A cloud that bends upward at the right end might be quadratic rather than linear, and a straight line through it will under-predict the middle and over-predict the ends. Compare the R-squared from a polynomial trendline with the linear one, and if the improvement is large and the curve is physically plausible, say so. Don't switch to a complex model just to chase a decimal place; the goal is a description that a reader can defend.
The zero trap concerns the intercept. In many datasets, x = 0 is far outside the observed range, so the intercept extrapolates beyond the data. A height-versus-age model for children doesn't sensibly predict a height at age zero, and the intercept value can be absurd even when the fit is excellent. Unless x = 0 is inside or near your range, report the slope as the headline and treat the intercept as a construction detail, not a finding.
These three traps share a remedy: keep the plot in front of you while you work with the numbers. The spreadsheet will happily compute a line through a U-shaped cloud, and it will not tell you the slope is meaningless. A thirty-second look at the scatter, the R-squared, and the residual pattern catches most of the ways a fit goes wrong. When the data genuinely can't support a straight line, saying so is a better answer than a tidy equation.
Report the Equation So Someone Else Can Reproduce It
Write your result as an equation with units, the sample size, and the R-squared. Something like "y = 0.6x + 2.2, where y is measured in kilograms and x in centimeters, based on 5 points, R-squared = 0.74." Every one of those elements matters for interpretation, and each is easy to omit when you're moving quickly. The units tell the reader what the slope means physically, and the sample size tells them how much weight to put on it.
Round sensibly. Slope and intercept precision should match the precision of your data. Reporting a slope of 0.60000003 when your measurements are whole numbers suggests a confidence you don't have. Two or three significant figures is usually right; drop trailing decimals that imply false precision. State the rounding rule so a reader who recomputes from your data gets the same displayed numbers.
Include the range of x-values over which the line was fit. Extrapolating outside that range is a separate, riskier activity, and flagging the range makes it obvious when you've done it. If you extend the line beyond the data, label it as extrapolation and describe the assumption behind it. Forecasts beyond the observed range deserve a caveat every time, because a linear trend that holds inside the data range often breaks outside it.
Also report which points, if any, were excluded and why. A footnote saying "one point at x = 12 excluded as a recorded instrument error" is honest and reproducible. Excluding without saying so is not. If nobody else can rebuild your line from your description, the report is incomplete, no matter how elegant the equation looks on the page.
FAQ
Does the line of best fit have to go through the origin?
No, unless you have a genuine reason to believe the relationship passes through zero. Most fits include an intercept term even when it's small. Forcing the line through the origin changes the slope estimate and can produce a worse fit, and it's only appropriate when a zero x-value must produce a zero y-value by the nature of the measurement. Check your software's "set intercept" option before using it, since it's off by default in typical spreadsheet trendlines.
Can I use the line to predict values outside my data range?
You can compute a prediction, but its reliability drops sharply outside the observed x-range, and many real relationships bend or reset beyond the data. Inside the range, the least-squares line is a reasonable summary; outside it, you're assuming the pattern persists. If a prediction beyond the range matters, collect data there or use a model that accounts for the underlying physics. Label any extrapolated value as an extrapolation in whatever you present.
What's the difference between a line of best fit and a regression line?
They're the same thing when the fit method is ordinary least squares, which is the default in almost every spreadsheet. A hand-drawn line of best fit is an approximation of that same line. The term "regression line" signals the statistical procedure, while "line of best fit" is the plain-English description. Once your line is fitted by least squares, both names are accurate, and the slope and intercept have the same interpretation either way.
Does R-squared of 0.30 mean the data is useless?
Not necessarily. An R-squared of 0.30 means 30% of the vertical variation is explained by the horizontal variable, which can still be a meaningful tendency when individual predictions are noisy. Whether that's useful depends on the stakes of your decision and whether you need to predict a single case or describe a broad pattern. Report it honestly rather than dismissing it, and pair it with the residual pattern before calling the model weak.
Why does my spreadsheet trendline disagree with my hand-drawn line?
The most common culprit is a swapped x and y, which gives the reciprocal slope, followed by an excluded point, a text value hidden in the x-column, or a chart type that treats the horizontal axis as categories. Check the chart's point count against your row count first, then verify the SLOPE argument order. If both lines were computed correctly, the disagreement is probably small and reflects the hand line's visual approximation, which is expected.
Is a steep slope the same as a strong relationship?
No. Slope measures how much y changes per unit of x, while strength measures how tightly the points cluster around the line. A steep line through widely scattered points has a weak relationship; a flat line through a tight cluster has a strong one. Look at R-squared or the residual spread to judge strength and read the slope for magnitude. Reporting only the slope hides the distinction.
What if I have two points that are identical in x but different in y?
A vertical pair of points at the same x cannot both be predicted well by a straight line, and the least-squares fit will place the line between them, splitting the vertical gap. This isn't an error; it reflects genuine variability in y at that x-value. Keep both points and report the vertical spread at that position as part of the noise. Removing one to tidy the plot would misrepresent your data.
How many points do I need for a trustworthy line?
There's no fixed threshold, but with two points the line is determined exactly and R-squared is 1 by arithmetic, which tells you nothing. With three to five, the result is highly sensitive to any single point. Many fields consider roughly twenty to thirty observations a reasonable base for a stable trend, though the right number depends on how much scatter your data has. Report the count with the fit so readers can weigh it themselves.
Final notes on scope and judgment
This article is general educational information about fitting straight lines to plotted data. It isn't a statistical consultation for a specific study, and the suitability of any model depends on how the data were collected, the measurement units, and the purpose of the analysis. For decisions where a regression result carries real consequences β clinical, financial, legal, or engineering β have the analysis reviewed by a qualified local professional in that field.