Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Trace of a Matrix


Symbolic visualization of tr(A) = sum of the main-diagonal entries.

Dimension of A (square)?Trace is defined only for square matrices. The trace of an n×n matrix A is the sum of its main-diagonal entries: tr(A) = a₁,₁ + a₂,₂ + … + aₙ,ₙ. Off-diagonal entries are ignored entirely.
A4×4
A4×4
a1,1
a1,2
a1,3
a1,4
a2,1
a2,2
a2,3
a2,4
a3,1
a3,2
a3,3
a3,4
a4,1
a4,2
a4,3
a4,4
Step 1 / 7

Step explanations

1Trace of a square matrix (4×4)
What is the trace of A? Trace is a single number assigned to every square matrix — we'll build it step by step.
Nothing is highlighted yet - only squareness has been established. Learn more about the opening scene · the scene order









Key Terms

Trace — the sum of the main-diagonal entries of a square matrix: tr(A)=a1,1+a2,2+⋯+an,n\text{tr}(A) = a_{1,1} + a_{2,2} + \cdots + a_{n,n}.

Main diagonal — the entries ai,ia_{i,i} where the row index equals the column index.

Square matrix — a matrix with the same number of rows and columns (n×nn \times n). Trace is defined only for square matrices.

Off-diagonal entries — entries ai,ja_{i,j} with i≠ji \neq j. They are completely ignored by the trace.

Scalar invariant — the trace returns a single number that is invariant under similarity transformations: tr(P−1AP)=tr(A)\text{tr}(P^{-1} A P) = \text{tr}(A).

Σ\Sigma notation — the trace can be written compactly as tr(A)=∑i=1nai,i\text{tr}(A) = \sum_{i=1}^{n} a_{i,i}.

Getting Started with the Visualizer

Set the size of AA and watch the trace build one diagonal entry at a time.

• Use the Dimension steppers to set the size of AA from 2×22 \times 2 up to 10×1010 \times 10 — both dimensions move together because AA must be square
• Hover the ? icon for a reminder that trace requires a square matrix
• The scene player starts by posing the question with no highlights, then reveals the main diagonal, then sweeps the diagonal entry by entry
• Use the speed selector and step log to control the pace and review prior steps

Reading the Scene Player

Each scene focuses on the diagonal of AA with three visual states.

• Pending entries (not yet counted) appear with a dashed green outline
• The current entry being added is highlighted in solid blue with a slight scale-up
• Counted entries turn solid green
• Off-diagonal cells stay neutral throughout — the trace ignores them completely
• The running formula tr(A)=a1,1+a2,2+⋯\text{tr}(A) = a_{1,1} + a_{2,2} + \cdots updates above with the same color coding

Choosing the Dimension

The dimension stepper controls the size of the square matrix AA.

• Smaller sizes (2×22 \times 2, 3×33 \times 3) make each scene easy to follow and show how short the trace sum is
• Larger sizes (up to 10×1010 \times 10) demonstrate how the same rule scales — exactly nn terms regardless of how many off-diagonal entries exist
• Cell size shrinks automatically as nn grows so the matrix stays readable
• Both row and column steppers are linked since trace only applies to square matrices

Scene Order

The animation follows a deliberate three-stage order.

• Pose — the matrix appears with no highlights; the question "what is the trace?" is asked first
• Reveal — the entire main diagonal is highlighted in blue, separating the entries that contribute from those that do not
• Sweep — one scene per diagonal entry, adding ak,ka_{k,k} to the running sum
• Outro — every diagonal entry is green and the complete formula is shown along with the Σ\Sigma notation

This order separates "what is the trace looking at?" from "what does the trace compute?" — two questions that are easy to conflate.

Scene 0: the Question, Before Anything Is Highlighted

The player opens on a deliberately blank slate. The matrix AA is drawn with every cell in its neutral grey, no diagonal marked, no running sum on screen — just the question of what the trace of this matrix is.

That restraint is the point. Before any procedure runs, the only thing established is that AA is square, 4×44 \times 4 at the default dimension, and that a single number is about to be extracted from it.
A4×4a1,1a1,2a1,3a1,4a2,1a2,2a2,3a2,4a3,1a3,2a3,3a3,4a4,1a4,2a4,3a4,4
Scene 0, frozen

Sixteen neutral cells and nothing else - no diagonal marked, no running sum. The only fact established so far is that A is square, which is the one thing the trace requires.

Squareness is the one precondition worth dwelling on. The trace is defined only for square matrices, because it needs entries where the row index and the column index agree — and in a 3×53 \times 5 matrix there is no a4,4a_{4,4} to reach for.

That is also why the dimension control offers a single number rather than a pair. Changing it from 4 to 7 rebuilds the scene list with three more sweep steps, but it can never produce a non-square matrix to take the trace of.

Scene 1: Revealing the Main Diagonal

The next scene turns exactly four cells blue — a1,1a_{1,1}, a2,2a_{2,2}, a3,3a_{3,3} and a4,4a_{4,4} — and leaves the other twelve grey.

Those four are the main diagonal: the cells whose row index equals their column index. Everything the trace does happens on them, and the twelve grey cells play no part in the calculation at all.
A4×4a1,1a1,2a1,3a1,4a2,1a2,2a2,3a2,4a3,1a3,2a3,3a3,4a4,1a4,2a4,3a4,4
Scene 1, frozen

The four cells where the row index equals the column index turn blue. The other twelve stay grey and take no part in the calculation.

A 4×44 \times 4 matrix holds sixteen numbers and the trace consults four of them, so it throws away three quarters of the matrix. That is a severe compression, and it is fair to ask what survives it.

Quite a lot, as it turns out. The trace is unchanged by transposing, since transposing swaps ai,ja_{i,j} with aj,ia_{j,i} and leaves ai,ia_{i,i} exactly where it was. It also equals the sum of the eigenvalues — so this fixed handful of cells encodes something about the matrix as a transformation, not merely about its bookkeeping. The key properties section takes that further.

The Sweep: One Diagonal Entry at a Time

    The middle scenes walk the diagonal from top-left to bottom-right, one cell per step, and the colouring carries three distinct meanings at once:

  • solid green — already added to the running sum
  • solid blue, slightly enlarged — the entry being added right now
  • dashed green outline — on the diagonal, still to come

  • The frozen picture below is the second sweep step. One entry is behind it, one is current, and two are still pending, so all three states are visible together.
A4×4a1,1a1,2a1,3a1,4a2,1a2,2a2,3a2,4a3,1a3,2a3,3a3,4a4,1a4,2a4,3a4,4
Sweep step 2 of 4, frozen

Three states at once: a11 solid green (already counted), a22 blue and slightly enlarged (being added now), a33 and a44 dashed (still pending).

The formula line beneath the matrix grows in step with the colouring, so the sum is assembled in front of you rather than presented finished. At this point it reads a1,1+a2,2a_{1,1} + a_{2,2}, with the remaining terms greyed until their turn.

Nothing here depends on the order. Addition is commutative, so sweeping bottom-right to top-left, or in any order at all, produces the same total — the left-to-right walk is a presentational choice, not part of the definition.

The Completed Trace

The final scene turns all four diagonal cells solid green and states the result in closed form:

tr⁡(A)=∑iai,i\operatorname{tr}(A) = \sum_i a_{i,i}

with every off-diagonal entry of AA formally ignored.
A4×4a1,1a1,2a1,3a1,4a2,1a2,2a2,3a2,4a3,1a3,2a3,3a3,4a4,1a4,2a4,3a4,4
Final scene, frozen

All four diagonal cells solid green. The caption states the closed form, sum over i of a(i,i), with every off-diagonal entry formally ignored.

Written as a sum over ii, the definition is size-independent: it reads identically whether the matrix is 2×22 \times 2 or 10×1010 \times 10, which is exactly what the dimension control demonstrates when you change nn and replay.

The compact form is also what makes the algebraic properties easy to check. Linearity, tr⁡(A+B)=tr⁡(A)+tr⁡(B)\operatorname{tr}(A + B) = \operatorname{tr}(A) + \operatorname{tr}(B), follows immediately because addition is entrywise and the diagonal of a sum is the sum of the diagonals. The cyclic property tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA) takes a little more work but comes from the same summation, and it is the reason the trace is invariant under a change of basis.

What the Trace Is

The trace of an n×nn \times n matrix AA is the sum of its main-diagonal entries:

tr(A)=a1,1+a2,2+⋯+an,n=∑i=1nai,i\text{tr}(A) = a_{1,1} + a_{2,2} + \cdots + a_{n,n} = \sum_{i=1}^{n} a_{i,i}


Trace is defined only for square matrices. Off-diagonal entries play no role at all — the trace ignores them completely. The result is a single scalar that summarizes one piece of information about AA, complementary to the determinant.

For comprehensive theory, see matrix operations.

Key Properties

The trace has a short list of clean algebraic properties.

• Linearity: tr(A+B)=tr(A)+tr(B)\text{tr}(A + B) = \text{tr}(A) + \text{tr}(B) and tr(kA)=k⋅tr(A)\text{tr}(kA) = k \cdot \text{tr}(A)
• Transpose invariance: tr(AT)=tr(A)\text{tr}(A^T) = \text{tr}(A) — the diagonal stays put under transposition
• Cyclic property: tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA), and more generally tr(ABC)=tr(BCA)=tr(CAB)\text{tr}(ABC) = \text{tr}(BCA) = \text{tr}(CAB)
• Similarity invariance: tr(P−1AP)=tr(A)\text{tr}(P^{-1} A P) = \text{tr}(A) — trace doesn't change under change of basis
• Sum of eigenvalues: for any square AA, tr(A)=∑iλi\text{tr}(A) = \sum_i \lambda_i where λi\lambda_i are the eigenvalues counted with multiplicity

The cyclic property is the workhorse — it's behind nearly every nontrivial trace identity.

Why It Matters

The trace appears throughout mathematics and applications because it captures the sum of eigenvalues in an arithmetic form that's easy to compute.

• Linear algebra: tr(A)=∑λi\text{tr}(A) = \sum \lambda_i — read off the eigenvalue sum without diagonalizing
• Differential geometry and physics: the trace of a stress or strain tensor measures volume change; the trace of a Hamiltonian relates to partition functions
• Machine learning: trace appears in covariance summaries, Frobenius norms (∥A∥F2=tr(ATA)\|A\|_F^2 = \text{tr}(A^T A)), and many regularization terms
• Inner product: the Frobenius inner product is ⟨A,B⟩F=tr(ATB)\langle A, B \rangle_F = \text{tr}(A^T B)
• Statistics: trace of a projection matrix counts the degrees of freedom of the projection

Anywhere a "total" or "sum of intrinsic quantities" of a square matrix is needed, the trace is the right tool.

Worked Example

Take AA as a 3×33 \times 3 matrix:

A=(27−105431−6)A = \begin{pmatrix} 2 & 7 & -1 \\ 0 & 5 & 4 \\ 3 & 1 & -6 \end{pmatrix}


The trace pulls out only the diagonal entries:

tr(A)=2+5+(−6)=1\text{tr}(A) = 2 + 5 + (-6) = 1


The other six entries (7, −1-1, 0, 4, 3, 1) are ignored entirely. Notice that for the same AA, the determinant uses every entry while the trace uses only three — they capture different aspects of the matrix.

Set the visualizer to 3×33 \times 3 and step through to see this picking-out process animated.

Common Mistakes

A few mistakes recur with trace.

• Trying to compute the trace of a non-square matrix — the trace is undefined for rectangular AA because there is no full main diagonal
• Confusing trace with determinant — both are scalar summaries of a square matrix, but trace sums diagonal entries while determinant computes a signed product across all permutations
• Forgetting the cyclic property is cyclic, not commutative — tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA) holds, but tr(ABC)≠tr(ACB)\text{tr}(ABC) \neq \text{tr}(ACB) in general
• Assuming trace equals the determinant of the diagonal — the trace is a sum, not a product
• Mixing up "diagonal" with "anti-diagonal" — trace uses entries where i=ji = j, not where i+j=n+1i + j = n + 1