Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Trace of a Matrix


Matrix Trace

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.







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
Learn More

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
Learn More

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
Learn More

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.
Learn More

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.
Learn More

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)=ktr(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(P1AP)=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.
Learn More

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 (AF2=tr(ATA)\|A\|_F^2 = \text{tr}(A^T A)), and many regularization terms
Inner product: the Frobenius inner product is A,BF=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.
Learn More

Worked Example

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

A=(271054316)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.
Learn More

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 commutativetr(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
Learn More

Related Concepts

Determinant — another scalar invariant of a square matrix, equal to the product of eigenvalues.

Eigenvalues — the trace equals their sum, the determinant equals their product.

Frobenius norm — defined as AF=tr(ATA)\|A\|_F = \sqrt{\text{tr}(A^T A)}.

Frobenius inner productA,BF=tr(ATB)\langle A, B \rangle_F = \text{tr}(A^T B).

Transpose — leaves the trace unchanged: tr(AT)=tr(A)\text{tr}(A^T) = \text{tr}(A).

Similarity transformation — leaves the trace invariant.

Identity matrixtr(In)=n\text{tr}(I_n) = n, since every diagonal entry equals 1.

Matrix multiplication — the cyclic property of trace (tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA)) is one of the most used trace identities.
Learn More