What is a Line of Best Fit Calculator?
A line of best fit (also called a best-fit line, trend line or least-squares line) is the straight line y = mx + b that passes as close as possible to all the points on a scatter plot. This line of best fit calculator finds it by the least-squares method, which makes the sum of the squared vertical gaps between the points and the line as small as possible. Enter your (x, y) data to get the equation, the slope and y-intercept in plain words, r and r², the residuals, a graph of the line, and a prediction for any x.
What the Line of Best Fit Calculator does
Give the calculator a set of (x, y) points and it returns the equation of the line of best fit in slope-intercept form, the slope and y-intercept with a plain-language meaning, the correlation r and r² to show how tightly the points follow the line, and a scatter plot with the line drawn in, so it also works as a line of best fit graph maker or trendline calculator. The hand-calculation table lists x, y, xy and x² with their totals plus every fitted value and residual, and the results include SSE, SST, SSR and the RMSE, so you can reproduce and check the result with a basic calculator, as many algebra and statistics courses require.
This page keeps things simple: one equation, a fit check and a quick prediction. If you need standard errors, p-values, an ANOVA table or prediction intervals, use the Linear Regression Calculator, which fits the same line with full inference. To plot the points first, use the Scatter Plot Maker; for the strength of the relationship on its own, the Correlation Coefficient Calculator. For data that bend, you need a curve of best fit instead: try the Quadratic Regression Calculator or the Exponential Regression Calculator.
How to use the Line of Best Fit Calculator
- Type each point into Data points (x, y) or paste two columns from a spreadsheet. Use Add point for more rows.
- Optionally enter a value in Predict y at x = to read a y value off the line.
- Read the equation y = mx + b, then the plain-words meaning of the slope and intercept under the results.
- Follow the step-by-step solution to see the sums Σx, Σy, Σxy and Σx², how they give m and b, and how SSE and r² measure the fit.
How to calculate the line of best fit by hand
To find the line of best fit equation without software, work from a table of column totals. These are the same steps the calculator shows in its solution, using the used-car data from the worked example below.
- Make a table with columns x, y, xy and x², and total each column: n = 9, Σx = 38, Σy = 172.3, Σxy = 626.5, Σx² = 208.
- Compute the slope: m = [nΣxy − (Σx)(Σy)] / [nΣx² − (Σx)²] = −908.9 / 428 = −2.1236.
- Compute the y-intercept: b = (Σy − mΣx) / n = 28.1107.
- Write the line as y = mx + b: y = −2.1236x + 28.1107.
- Check it passes through the mean point (x̄, ȳ) = (4.2222, 19.1444), and that the residuals y − line add to zero.
- Judge the fit with r or r², or with SSE (the smaller the better for the same data). Here r = −0.9904 and r² = 0.9809.
Line of best fit formula
These are the standard least-squares formulas (the best fitting line formula) written with column totals, which is the easiest form to use by hand.
| Symbol | Meaning |
|---|---|
| n | number of points |
| Σx, Σy | sum of the x values, sum of the y values |
| Σxy | sum of each x multiplied by its own y |
| Σx² | sum of the squared x values |
| x̄, ȳ | mean of x and mean of y; the line always passes through (x̄, ȳ) |
| SSE | sum of squared residuals, the quantity the line makes as small as possible |
Statistics books often write the same line as ŷ = b₀ + b₁x, where b₁ is the slope (m here) and b₀ is the intercept (b here).
The formulas follow standard references: Penn State STAT 462, lesson 2.2: What is the “Best Fitting Line”?, the NIST/SEMATECH e-Handbook of Statistical Methods, §4.4.3.1: Least Squares and OpenStax Introductory Statistics 2e, §12.3: The Regression Equation.
Worked example
Worked example: age and price of used cars
Problem. Nine used cars of the same model have ages x (years) of 1, 2, 2, 3, 4, 5, 6, 7, 8 and prices y ($1,000s) of 26.5, 23.4, 24.8, 21.0, 19.6, 16.4, 15.9, 12.8, 11.9. Find the line of best fit and estimate the price of a 5½-year-old car.
- 01Column totals: n = 9, Σx = 38, Σy = 172.3, Σxy = 626.5, Σx² = 208.
- 02Slope: m = (9 × 626.5 − 38 × 172.3) / (9 × 208 − 38²) = (5638.5 − 6547.4) / (1872 − 1444) = −908.9 / 428 = −2.1236.
- 03Intercept: b = (172.3 − (−2.1236)(38)) / 9 = (172.3 + 80.6967) / 9 = 28.1107.
- 04Equation: y = −2.1236x + 28.1107. Check: at x̄ = 4.2222 the line gives 19.1444 = ȳ.
- 05Fit: r = −908.9 / √(428 × 1967.78) = −0.9904, so r² = 0.9809. SSE = 4.1824 out of SST = 218.6422, and the largest residual is −1.09 (the 5-year-old car, about $1,090 below the line).
- 06Prediction at x = 5.5: y = −2.1236 × 5.5 + 28.1107 = 16.4310.
Answer. Each extra year of age knocks about $2,124 off the price, and the line puts the price of a new car (x = 0) near $28,100. A 5½-year-old car is predicted to sell for about $16,400, and the line misses the actual prices by about $680 on average (RMSE).
SSE, SST and SSR: how well does the line fit?
SSE (sum of squared errors, or residual sum of squares) is Σ(y − line)², the variation the line leaves unexplained. Least squares picks the one line that makes SSE as small as possible. SST (total sum of squares) is Σ(y − ȳ)², the total variation of y around its mean. SSR (regression sum of squares) is the part the line explains, and for a least-squares line SST = SSR + SSE.
Dividing gives r² = SSR / SST = 1 − SSE / SST, the share of the variation in y the line accounts for. The RMSE = √(SSE / n) is the typical size of a residual in the units of y; regression software often reports the standard error of the estimate √(SSE / (n − 2)) instead, which is slightly larger.
| Quantity | Formula | Used-car example |
|---|---|---|
| SSE | Σ(y − ŷ)² | 4.1824 |
| SST | Σ(y − ȳ)² | 218.6422 |
| SSR | SST − SSE | 214.4598 |
| r² | SSR / SST | 0.9809 |
| RMSE | √(SSE / n) | 0.6817 ($682) |
| Standard error of the estimate | √(SSE / (n − 2)) | 0.7730 ($773) |
How to calculate b₀ and b₁ in linear regression
Statistics books write the same line as ŷ = b₀ + b₁x. The slope b₁ is m on this page and the intercept b₀ is b. In deviation form, b₁ = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = Sxy / Sxx and b₀ = ȳ − b₁x̄. Both forms give identical numbers: for the car data, Sxy = −100.9889 and Sxx = 47.5556, so b₁ = −2.1236 and b₀ = 19.1444 − (−2.1236)(4.2222) = 28.1107.
The column-totals form is quicker with a basic calculator; the deviation form is less prone to rounding error when the x values are large. You can also get the slope from the correlation: b₁ = r × (s_y / s_x).
Drawing a best-fit line by eye vs least squares
A best fit straight line drawn by eye with a ruler is a reasonable sketch, but two people will draw two different lines. Least squares gives one definite answer: it is the only line that minimizes Σ(y − line)², and it always passes through the mean point (x̄, ȳ) with residuals that sum to zero.
A quick by-eye check is still useful: about half the points should sit above the least-squares line and half below, with no long run of points on one side. A run like that suggests the data curve and a straight line is the wrong shape.
Choosing the line of best fit on a multiple-choice question
Tests often show a scatter plot and ask which equation is the line of best fit. You can usually eliminate wrong options without computing anything:
- Sign of the slope: points rising left to right need a positive m; falling points need a negative m.
- Size of the slope: pick two points on the drawn trend, say x = 0 and x = 10, and check that the rise over run is about right.
- Intercept: extend the trend to x = 0 and compare with b in each option.
- Mean point: the correct line passes through (x̄, ȳ). If you can find the two means, plug them into each option.
- Balance: roughly as many points should sit above the line as below it.
Line of best fit calculator vs linear regression calculator
Both find the same least-squares line. Use this page when you need the equation, a graph and the working for homework, a lab report or a quick forecast. Use the Linear Regression Calculator when you need to test whether the slope is significantly different from zero, report standard errors and p-values, or put confidence and prediction intervals around a predicted value.
Common use cases
- Homework and exams: checking a hand-calculated slope and intercept, with every sum shown.
- Science labs: fitting a straight line to measurements, such as extension against load, and reading off the gradient.
- Quick forecasts: estimating a value between measured points, like the price of a car of a given age.
- Presentations: adding a trend line to a scatter plot and stating the trend in one sentence.
Assumptions and limitations
- Straight lines only: if the points curve, the best straight line can still be a poor description. Look at the plot and the residual column.
- Interpolation is safer than extrapolation: predictions inside the range of your x values are far more trustworthy than predictions beyond it.
- Outliers pull the line: because gaps are squared, one far-off point can tilt the line noticeably.
- No uncertainty shown: this page gives the line itself, not confidence or prediction intervals. Use the Linear Regression Calculator for those.
- y on x only: the line minimizes vertical gaps, so it predicts y from x. Regressing x on y gives a different line unless r = ±1.
- Association, not cause: a clear trend line does not show that x causes y.
Frequently asked questions
How do you calculate the line of best fit?
What is the equation for the line of best fit?
What is SSE, SST and SSR?
How do you calculate b0 and b1 in linear regression?
Does the line of best fit have to go through the origin?
Does the line of best fit have to pass through any of the data points?
Is a line of best fit the same as a regression line?
What is the difference between a line of best fit and a curve of best fit?
How do I get the line of best fit in Excel or Google Sheets?
Cite this page
Statculator. (2026, November 14). Line of Best Fit Calculator. Retrieved November 14, 2026, from https://statculator.com/correlation-regression/line-of-best-fit-calculator/