Basic statistics

Line of Best Fit Calculator: Slope, Intercept, r and r² with the Working Table and Graph

Paste your x and y values and get the least-squares line of best fit y = a + bx, with the full Σx, Σy, Σxy and Σx² working table, the correlation r, r², a prediction for any x and a scatter plot. Ideal for matric, FSc, CBSE and first-year university statistics. Nothing is saved.

✅ No login needed100% freeRuns in your browserNothing savedYour data stays on your device
Line of Best Fit Calculator✅ Free · no login📚 Cite this tool
Your data never leaves your PC. Everything you type is calculated on your own computer or phone. Nothing is saved, not even in your browser, and it is gone when you close the page. Nothing is uploaded, stored or seen by Codanics, and no login is needed.
  • PriceFree, no login or sign-up needed
  • Your dataCalculated in your browser; nothing is saved
  • Works onPhone, tablet or computer, any modern browser
  • Made byDr. Muhammad Aammar Tufail, Codanics
  • Published24 November 2026
  • Last updated24 November 2026

📚 How to cite this tool

This tool is free. If it helped your thesis, paper, report or assignment, please cite it. It keeps the tools free and helps other students find them.

Citation · APA 7th edition

Tufail, M. A. (2026). Line of best fit calculator [Online tool]. Codanics. Retrieved 24 November 2026, from https://codanics.com/tools/line-of-best-fit-calculator/

In-text citation: (Tufail, 2026) · Narrative: Tufail (2026)

The access date is today’s date, filled in automatically. Author: Muhammad Aammar Tufail. Published 24 November 2026.

🚀 Follow Codanics channel on WhatsApp for more updatesNew free tools, scholarships, PhD positions and research tips, straight to your phone. Free lessons on YouTube too.

How to use the line of best fit calculator

  1. Paste your data with one x, y pair per line (for example hours studied and marks). Two columns copied from Excel work too.
  2. The slope, intercept, equation, r and r² appear instantly, with the Σx, Σy, Σxy and Σx² working table below.
  3. Type an x value to predict y from the line.
  4. Check the scatter plot: the points should follow a straight-line pattern for the line to make sense.

What is the line of best fit?

The line of best fit (least-squares regression line) is the straight line y = a + bx that makes the sum of the squared vertical distances from the points to the line as small as possible. The slope b tells you how much y changes for each 1-unit increase in x. The intercept a is the predicted y when x = 0.

Formulas for slope, intercept and r

b = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) a = ȳ − b·x̄ r = (nΣxy − ΣxΣy) ÷ √[(nΣx² − (Σx)²)(nΣy² − (Σy)²)]

These are the “by hand” formulas taught in Pakistani FSc/ICS and Indian Class 11–12 statistics. The calculator builds the same table you would draw on paper.

Worked example: hours studied vs marks

Eight students: hours = 1 to 8; marks = 52, 55, 61, 64, 68, 71, 77, 80.

nΣxΣyΣxyΣx²Σy²
8365282,54620435,540
  1. b = (8 × 2,546 − 36 × 528) ÷ (8 × 204 − 36²) = 1,360 ÷ 336 = 4.0476
  2. a = 66 − 4.0476 × 4.5 = 47.7857
  3. Line: ŷ = 47.79 + 4.05x. Each extra hour adds about 4 marks.
  4. r = 0.9972 and r² = 0.9944: a very strong positive relationship; the line explains 99.4% of the variation.
  5. Prediction for 10 hours: 47.79 + 4.05 × 10 ≈ 88.3 marks (an extrapolation, so treat it with care).

How to interpret r

|r|Strength (rule of thumb)
0.9 to 1.0Very strong
0.7 to 0.9Strong
0.5 to 0.7Moderate
0.3 to 0.5Weak
below 0.3Very weak or none

Common mistakes

  • Correlation is not causation. A strong r does not prove x causes y.
  • Extrapolation. Predictions far outside your x range can be badly wrong.
  • Curved patterns. If the scatter plot bends, a straight line is the wrong model.
  • Outliers. One extreme point can pull the line a long way. Look at the plot.
Need p-values, confidence intervals for the slope and residual plots? Use the correlation and regression calculator. For several predictors, try the multiple regression calculator.
Learn the statistics behind these numbers. Codanics has free statistics, R and Python lessons on YouTube and full courses for researchers.

Frequently asked questions

How do you find the line of best fit?

Work out n, Σx, Σy, Σxy and Σx². Then slope b = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) and intercept a = ȳ − b·x̄. The line is y = a + bx.

What does the slope of the line of best fit mean?

The slope is the average change in y for each 1-unit increase in x. A slope of 4.05 marks per hour means each extra hour of study goes with about 4 more marks.

What is the difference between r and r²?

r (from −1 to 1) shows the direction and strength of a straight-line relationship. r² (from 0 to 1) is the share of the variation in y explained by the line. r = 0.9 gives r² = 0.81, or 81%.

Is the line of best fit the same as linear regression?

Yes. The least-squares line of best fit is the simple linear regression of y on x.

How many data points do I need?

At least three, but more is better. With two points the line passes through both and r is always ±1, which tells you nothing.

Is my data saved or uploaded?

No. The calculation runs in your browser and nothing is saved or uploaded.

Do I need to log in or create an account to use the line of best fit calculator?

No. There is no login, no sign-up and no email required. Open the page and start using it straight away, for free, on any device.

How do I cite this tool in my thesis or paper?

Use the citation box on this page. In APA 7th edition: Tufail, M. A. (2026). Line of best fit calculator [Online tool]. Codanics. Retrieved [date you used it], from https://codanics.com/tools/line-of-best-fit-calculator/. BibTeX, RIS (EndNote, Mendeley, Zotero), MLA, Harvard, Chicago and Vancouver formats are also available.

Free guides and courses from Codanics

More free tools

See all free Codanics tools → · Codanics on YouTube · WhatsApp channel

Made by Dr. Muhammad Aammar Tufail, Codanics. First published 24 November 2026, last updated 24 November 2026. Found a bug or have an idea for a new tool? Tell us on the WhatsApp channel or in the comments on YouTube. Results are for learning and planning; check important analyses with a statistician or your supervisor.