Matrix Trace Calculator

Add the diagonal entries of a square matrix to find its trace.

Math and PercentUpdated 2026-11-192 min read
Matrix Trace Calculator
Up to 6 rows and 6 columns, with one entry per row. Separate entries with spaces or commas and rows with semicolons.
Trace
...
Matrix size...
Diagonal entries...

What it does

The trace of a square matrix is one of the simplest numbers you can extract from it. You take the entries where the row number and column number match, from the top left down to the bottom right, and add them together.

This tool accepts square matrices of up to six rows and six columns. Enter numbers separated by spaces or commas and put a semicolon between rows. The page opens on the three by three matrix containing one through nine.

Although the definition is short, the trace turns out to be useful. It is unchanged by a change of basis, it equals the sum of the eigenvalues, and it satisfies the identity that the trace of a product is the same whichever order you multiply two conformable matrices.

Because the calculation is just a sum, there is no rounding in the result beyond how the entries themselves are displayed. The tool also lists the diagonal entries so you can check the addition by hand.

A rectangular matrix has no main diagonal in the sense needed here, so the tool rejects rows of unequal length instead of guessing which entries to add.

How to use

  1. Type the rows of a square matrix.
  2. Separate entries with spaces or commas and rows with semicolons.
  3. Read the trace as the main result.
  4. Check the diagonal row to confirm which entries were added.
  5. Use the size row to verify how many rows and columns the tool found.
  6. Try the identity matrix to see that its trace equals its dimension.

Formula

tr(A) = sum from i = 1 to n of a(i,i), for an n by n matrix A
A
A square matrix with n rows and n columns.
a(i,i)
The entry in row i and column i, on the main diagonal.
tr(A)
The sum of those n diagonal entries.

The main diagonal runs from the upper left to the lower right. A useful check is that the trace of A plus B equals the trace of A plus the trace of B, and the trace of a scalar multiple scales by that scalar. For a square matrix the trace also equals the sum of eigenvalues counted with algebraic multiplicity.

Worked example

Example: a 3 by 3 matrix

The page opens with rows 1 2 3; 4 5 6; 7 8 9.

  1. Identify the diagonal entries: row 1 column 1 is 1.
  2. Row 2 column 2 is 5.
  3. Row 3 column 3 is 9.
  4. Add them: 1 plus 5 plus 9 is 15.
  5. The entries away from the diagonal do not affect the result.
  6. The tool reports trace 15, size 3 x 3 and diagonal 1, 5, 9.

Reference table

Traces of sample square matrices
Matrix rowsDiagonalTrace
1 2 3; 4 5 6; 7 8 91, 5, 915
1 2; 3 41, 45
2 0 0; 0 2 0; 0 0 22, 2, 26
1 0; 0 -11, -10

Limits

  • Accepts at most 6 rows and 6 columns.
  • The matrix must be square, so every row needs the same number of entries.
  • Entries must be numbers between minus 1,000,000,000 and 1,000,000,000.
  • The trace is defined only for square matrices.

Common mistakes

  • Adding the entries of the first row instead of the diagonal.
  • Using the anti diagonal from top right to bottom left.
  • Trying to take the trace of a rectangular matrix.
  • Counting the diagonal entry in every row twice.
  • Assuming the trace depends on the off diagonal entries.

Try it yourself

Quick checks. Answers sit tucked under each question.

Trace of 1 2; 3 4?

5, from 1 plus 4.

Trace of the 3 by 3 identity matrix?

3, because each of the three diagonal entries is 1.

Trace of 1 0; 0 -1?

0, because 1 plus negative 1 is zero.

Questions

What is a trace?

The sum of the diagonal entries of a square matrix.

Can a non square matrix have a trace?

No. The trace is defined only for square matrices.

How does the trace relate to eigenvalues?

It equals the sum of the eigenvalues counted with algebraic multiplicity.

Does reordering rows change the trace?

Usually yes, because different entries then sit on the diagonal.

What is the trace of the identity matrix?

Its dimension n, since it has n ones on the diagonal.

Is the trace the same as the determinant?

No. They are different functions, though both are defined only for square matrices.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.