BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)
Updated:

Sum of Squares Calculator

Paste your numbers and get the sum of squares, Σ(x − x̄)², with the mean, variance, standard deviation and a deviation table. Switch tabs for regression (SST, SSR, SSE), one-way ANOVA (between and within), or the plain sums used in algebra. This tool is part of our free statistics calculators collection, and it runs entirely in your browser.

Sum of Squares Calculator

Formula SS = Σ(x − x̄)² Use when you have one list of numbers
Separate values with commas, spaces or new lines. Minimum two values.
Formula SST = SSR + SSE Use when you fit a line to x and y

Enter x and y in the same order. Both lists need the same length, at least three pairs. The calculator fits an ordinary least-squares line with an intercept.

Formula SST = SSB + SSW Use when you compare two or more group means
Put each group on its own line and separate values with commas or spaces. Do not type group names. Group sizes can differ.
Formula 1² + 2² + … + n² = n(n+1)(2n+1) / 6 Use for algebra and programming

Run a calculation in any other tab first. The most recent one is written out here, one substitution at a time.

No data yet. Enter values in the Data Set, Regression, ANOVA or First n tab.

What Is the Sum of Squares?

The sum of squares (SS) is the total of the squared differences between each value and a reference point, usually the mean. It measures how spread out a data set is. For the numbers 4, 5, 8, 7, 11, 4 and 3, the mean is 6 and the sum of squares is 48.

Squaring does two jobs. It stops deviations above the mean from cancelling deviations below it, and it weights a value twice as far from the mean four times as heavily. Divide SS by n − 1 and you get the sample variance. Take the square root of that and you have the standard deviation. The sum of squares is the raw material for both.

The name covers more than one calculation, which is why the tool above has tabs. A statistics student, a regression user and someone doing algebra homework can all type “sum of squares” and mean different things. The next section sorts them out. If you only need a quick spread measure, the descriptive statistics calculator reports SS alongside the mean, median and quartiles, and every other tool lives in the calculators hub.

Which Sum of Squares Do You Need?

Match the sum of squares to your data: one list uses SS about the mean, x and y pairs use SST, SSR and SSE, groups use SSB and SSW, and plain squaring uses the raw Σx².

Table: Four Meanings of “Sum of Squares” and the Calculator Tab for Each

What you haveNameFormulaTab
One list of numbers, you want spreadSum of squared deviations (corrected SS)Σ(x − x̄)²Data Set
x and y pairs, you fit a lineSST, SSR, SSEΣ(y−ȳ)², Σ(ŷ−ȳ)², Σ(y−ŷ)²Regression
Two or more groups, you compare meansSS between, SS within, SS totalΣnᵢ(x̄ᵢ−x̄)², ΣΣ(x−x̄ᵢ)²ANOVA
Numbers you simply square and addRaw sum of squaresΣx², n(n+1)(2n+1)/6, a²+b²First n / Two Numbers

The first three are all “corrected” sums: each subtracts a mean before squaring. The fourth does not. That difference drives the most common mistake with this topic, covered in the raw versus corrected section below.

Sum of Squares Formula

For a data set, SS = Σ(x − x̄)²: subtract the mean from every value, square each result, and add them up. An equivalent shortcut, SS = Σx² − (Σx)²/n, avoids computing the mean first.

Definition (Corrected SS)

SS = Σ(xᵢ − x̄)² Where: xᵢ = each value x̄ = mean of the values n = number of values

Computational Formula

SS = Σx² − (Σx)² / n Same answer as the definition. Faster by hand, but it can lose precision on large numbers.

Regression

SST = Σ(y − ȳ)² SSR = Σ(ŷ − ȳ)² SSE = Σ(y − ŷ)² SST = SSR + SSE R² = SSR / SST = 1 − SSE / SST

One-Way ANOVA

SSB = Σ nᵢ(x̄ᵢ − x̄)² SSW = ΣΣ(x − x̄ᵢ)² SST = SSB + SSW MS = SS / df, F = MSB / MSW

The shortcut deserves one warning. Subtracting two large, nearly equal numbers throws away significant digits in floating-point arithmetic. For values like 1,000,000.1 and 1,000,000.2, the definition gives a clean answer and the shortcut can return a visibly wrong one. The calculator above uses the definition (two passes through the data) for that reason, and shows the shortcut value beside it as a cross-check.

How to Calculate the Sum of Squares by Hand

Find the mean, subtract it from each value, square the differences, and add them. Here is the full method on the data 4, 5, 8, 7, 11, 4, 3.

1
Find the mean

The seven values add to 42, so x̄ = 42 / 7 = 6.

2
Subtract the mean from each value

The deviations are −2, −1, 2, 1, 5, −2 and −3. They add to 0. If yours do not, recheck the mean.

3
Square each deviation

4, 1, 4, 1, 25, 4 and 9.

4
Add the squares

4 + 1 + 4 + 1 + 25 + 4 + 9 = 48. That is the sum of squares.

5
Cross-check with the shortcut

Σx² = 16 + 25 + 64 + 49 + 121 + 16 + 9 = 300. Then 300 − 42²/7 = 300 − 252 = 48. Both routes agree.

6
Turn it into variance and SD if needed

Sample variance = 48 / 6 = 8, so the sample SD is √8 ≈ 2.828. Population variance = 48 / 7 ≈ 6.857.

Result: SS = 48, mean = 6, n = 7. Load the example in the Data Set tab to see the same deviation table.

Raw vs Corrected Sum of Squares

The raw sum of squares, Σx², squares the values as they are. The corrected sum of squares, Σ(x − x̄)², squares their distance from the mean. For the example above they are 300 and 48.

The trap: variance, standard deviation, SST and ANOVA all use the corrected sum. If you plug Σx² into a variance formula, the answer is inflated by the size of the mean. Spreadsheet users hit this when they reach for SUMSQ instead of DEVSQ.

One more place the distinction appears: regression software without an intercept. Most packages then measure the total sum of squares about zero rather than about the mean, and R² changes meaning. The Python library statsmodels exposes both versions as centered_tss and uncentered_tss. If your R² looks too good, check which one was used.

SST, SSR and SSE in Regression

SST is the total variation in y, SSR is the part a fitted line explains, and SSE is the part it leaves unexplained. For a least-squares line with an intercept, SST = SSR + SSE. R² is the explained share, SSR / SST.

Here is a small case you can reproduce in the Regression tab. Take x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5. The mean of y is 4, and the fitted line is ŷ = 2.2 + 0.6x.

Table: Worked Regression Example, x = 1–5, y = 2, 4, 5, 4, 5

QuantityCalculationValuedf
SST4 + 0 + 1 + 0 + 16.04
SSE0.64 + 0.36 + 1 + 0.36 + 0.042.43
SSRSST − SSE3.61
R²3.6 / 6.00.60—

The line explains 60% of the variation in y. The identity SST = SSR + SSE is a property of ordinary least squares with an intercept. It breaks for models without an intercept and for penalised fits such as ridge and lasso, where the fitted values are not a pure least-squares projection. For the full regression picture, see simple linear regression, R-squared, residuals and OLS regression. To see the residual segments on your own data, try the regression scatter plot tool.

SSR Means Two Different Things: Notation Across Sources

“SSR” is the regression sum of squares in some sources and the residual sum of squares in others, so always check the definition before copying a formula. DataCamp points out that SSE is also written RSS, ESS or even SSR, and Wikipedia warns against confusing SSR with the residual sum of squares.

Table: Names for the Three Regression Sums of Squares

Source or conventionExplained by the modelLeft over (residual)Total
This page, many intro coursesSSR (regression)SSE (error)SST
Econometrics-style textsESS (explained)RSS (residual)TSS
Some textbooksSSM or SSRSSR or SSESST
Python statsmodelsessssrcentered_tss
Excel LINEST, row 5SS regression (column 1)SS residual (column 2)use DEVSQ(y)

The statsmodels row is the one that catches people. Its ssr attribute is the sum of squared residuals, which most regression courses call SSE. When a formula looks right but the number is wrong, a swapped name is the first thing to test.

Sum of Squares in ANOVA

In one-way ANOVA, the total sum of squares splits into SS between groups (differences among group means) and SS within groups (scatter inside each group): SST = SSB + SSW. Dividing each by its degrees of freedom gives mean squares, and their ratio is the F statistic.

Take three groups of six: A = 6, 8, 4, 5, 3, 4; B = 8, 12, 9, 11, 6, 8; C = 13, 9, 11, 8, 7, 12. The group means are 5, 9 and 10, and the grand mean is 8. Paste them into the ANOVA tab to reproduce the table below.

Table: One-Way ANOVA Table for the Three-Group Example

SourceSSdfMSF
Between groups84242.009.265
Within groups68154.533—
Total15217——

With F = 9.265 on 2 and 15 degrees of freedom, p ≈ 0.0024, so the group means differ by more than chance would usually produce. The share of variation tied to group membership is SSB / SST = 84 / 152 ≈ 0.55. Penn State’s STAT 415 notes on the ANOVA table lay out the same decomposition. To go further, read the ANOVA guide and its worked examples, look up critical values in the F-table, or use the full ANOVA calculator and two-way ANOVA calculator.

Sum of Squares vs Variance vs Standard Deviation

Variance is the sum of squares divided by its degrees of freedom (n − 1 for a sample), and standard deviation is the square root of variance. SS grows with sample size, so it cannot compare data sets of different lengths. Variance and SD can.

Table: From Sum of Squares to SD, Using 4, 5, 8, 7, 11, 4, 3

MeasureFormulaValueUnits
Sum of squaresΣ(x − x̄)²48squared
Sample varianceSS / (n − 1)8squared
Population varianceSS / n6.857squared
Sample SD√(SS / (n − 1))2.828original

Why square instead of taking absolute values? Squares are smooth, so calculus can minimise them, and that is exactly how least-squares regression finds its line. Squares also punish a single large miss more than several small ones, which is often what you want. The cost is that one outlier can dominate the total. Our standard deviation vs variance article compares the two in more detail, and measures of dispersion puts SS in context with range and IQR.

Sum of Squares in Excel, Google Sheets, Python and R

In Excel and Google Sheets, DEVSQ returns the corrected sum of squares and SUMSQ returns the raw one. For 4, 5, 8, 7, 11, 4, 3, DEVSQ gives 48 and SUMSQ gives 300. Microsoft’s own DEVSQ documentation uses this same data, and Google’s DEVSQ help page notes it equals (COUNT − 1) × VAR.

Table: DEVSQ vs SUMSQ on the Example Data

FunctionComputesResultUse for
DEVSQ(A2:A8)Σ(x − x̄)²48Variance, SD, SST
SUMSQ(A2:A8)Σx²300Algebra, norms, raw totals
VAR.S(A2:A8)*(COUNT(A2:A8)-1)SS via variance48Cross-check

Code Examples

# Python (NumPy): data set import numpy as np x = np.array([4, 5, 8, 7, 11, 4, 3]) ss = np.sum((x - x.mean()) ** 2) # 48.0 corrected raw = np.sum(x ** 2) # 300 raw # Python (statsmodels): regression import statsmodels.api as sm X = sm.add_constant([1, 2, 3, 4, 5]) fit = sm.OLS([2, 4, 5, 4, 5], X).fit() fit.centered_tss # SST = 6.0 fit.ess # SSR = 3.6 (regression) fit.ssr # SSE = 2.4 (residual, despite the name)
# R x <- c(4, 5, 8, 7, 11, 4, 3) sum((x - mean(x))^2) # 48 xx <- 1:5; y <- c(2, 4, 5, 4, 5) fit <- lm(y ~ xx) sse <- sum(resid(fit)^2) # 2.4 sst <- sum((y - mean(y))^2) # 6 ssr <- sst - sse # 3.6 # Excel: regression sums of squares from LINEST =INDEX(LINEST(y, x, TRUE, TRUE), 5, 1) # SSR =INDEX(LINEST(y, x, TRUE, TRUE), 5, 2) # SSE

For more on getting statistics out of code, see statistics for Python and statistical analysis with Microsoft tools. The statsmodels attributes are listed in its RegressionResults reference.

Sum of Squares of the First n Natural Numbers

The sum of the squares of the first n natural numbers is n(n + 1)(2n + 1) / 6. For n = 10 that is 10 × 11 × 21 / 6 = 385. This is the plain, uncorrected kind of sum of squares, used in algebra and programming rather than in data analysis.

Table: Sums of Squares for Natural, Even and Odd Numbers

nFirst n natural
n(n+1)(2n+1)/6
First n even
2n(n+1)(2n+1)/3
First n odd
n(2n−1)(2n+1)/3
555220165
103851,5401,330
202,87011,48010,660
5042,925171,700166,650
100338,3501,353,4001,333,300

The even-number sum is always four times the natural-number sum, because (2k)² = 4k². For two numbers, a² + b² = (a + b)² − 2ab, so 3 and 4 give 9 + 16 = 25. A classic programming puzzle, Project Euler problem 6, asks for the gap between the square of the sum and the sum of the squares of 1 to 100: 5050² − 338,350 = 25,164,150.

Common Mistakes

Most wrong answers come from five slips, and the first two account for the majority.

1
Using Σx² where Σ(x − x̄)² is needed

The raw sum ignores where the data are centred. Use DEVSQ, not SUMSQ, for spread.

2
Mixing up SSR and SSE

Check how your textbook or software defines SSR before you read R² off it.

3
Squaring the sum instead of summing the squares

(Σx)² and Σx² differ. For 4, 5, 8, 7, 11, 4, 3 they are 1,764 and 300.

4
Dividing by n when you have a sample

Sample variance divides SS by n − 1. Dividing by n understates the spread.

5
Expecting SST = SSR + SSE without an intercept

The identity needs a least-squares fit with an intercept.

Sum of squares sits underneath variance, regression and ANOVA. These pages cover each of those, and the calculators hub lists every tool.

Sources and Further Reading

External references used on this page:

Frequently Asked Questions

The sum of squares is the total of squared differences between each value and a reference point, usually the mean. For a data set it is SS = Σ(x − x̄)² and it measures spread. For the values 4, 5, 8, 7, 11, 4 and 3 the mean is 6 and SS is 48. Dividing SS by n − 1 gives the sample variance.

Find the mean, subtract it from every value, square each difference, and add the squares. With 4, 5, 8, 7, 11, 4 and 3 the mean is 6, the squared deviations are 4, 1, 4, 1, 25, 4 and 9, and they add to 48. The shortcut Σx² − (Σx)²/n gives the same answer: 300 − 252 = 48.

SST is the total variation in y about its mean, SSR is the part explained by the fitted regression line, and SSE is the part left unexplained (the residuals). For a least-squares line with an intercept, SST = SSR + SSE, and R² = SSR / SST.

It depends on the source. Many intro courses use SSR for the regression (explained) sum of squares and SSE for the error. Other texts use SSR or RSS for the residual sum of squares and ESS for the explained part. Python’s statsmodels uses ssr for the residual sum. Check the definition before copying a formula.

The sum of the squared values, Σx², is the raw sum of squares. The sum of squares used for variance, SST and ANOVA is the corrected one, Σ(x − x̄)², which subtracts the mean first. For 4, 5, 8, 7, 11, 4 and 3 the raw sum is 300 and the corrected sum is 48.

It is n(n + 1)(2n + 1) / 6. For n = 10 the result is 385, and for n = 100 it is 338,350. The sum of the first n even squares is 2n(n + 1)(2n + 1) / 3, and the first n odd squares is n(2n − 1)(2n + 1) / 3.

Use DEVSQ for the corrected sum of squares and SUMSQ for the raw sum. With 4, 5, 8, 7, 11, 4 and 3 in A2:A8, DEVSQ(A2:A8) returns 48 and SUMSQ(A2:A8) returns 300. Google Sheets documents DEVSQ as equal to (COUNT − 1) × VAR.

No. Every term is a square, so SS is zero or positive. It equals zero only when every value is identical, so there is no spread at all. A negative result in a hand calculation means an arithmetic slip, often from subtracting the shortcut terms in the wrong order.

Sample variance is SS divided by n − 1, population variance is SS divided by n, and standard deviation is the square root of the variance. With SS = 48 and n = 7, the sample variance is 8 and the sample SD is about 2.828.

A large SS means the values sit far from the mean overall, but SS also grows with the number of observations, so compare variance or SD instead when data sets differ in size. In regression, a large SSE relative to SST means the line fits poorly. In ANOVA, a large SSB relative to SSW points to real differences between groups.