Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Trace of a Matrix






The Simplest Matrix Invariant

The trace of a square matrix is the sum of its diagonal entries — an operation so simple it barely seems worth naming. Yet this single number equals the sum of the eigenvalues, remains unchanged under similarity transformations, and turns up in inner products, commutator identities, and optimization gradients. Its simplicity is precisely what makes it powerful.



Definition

For an n×nn \times n matrix AA, the trace is the sum of the entries on the main diagonal:

Trace Definition
tr(A)=∑i=1naii=a11+a22+⋯+ann\text{tr}(A) = \sum_{i=1}^{n} a_{ii} = a_{11} + a_{22} + \cdots + a_{nn}

The trace is defined only for square matrices — a rectangular matrix has no trace.

For example, if A=(314159265)A = \begin{pmatrix} 3 & 1 & 4 \\ 1 & 5 & 9 \\ 2 & 6 & 5 \end{pmatrix}, then tr(A)=3+5+5=13\text{tr}(A) = 3 + 5 + 5 = 13. The off-diagonal entries play no role.

The trace of the n×nn \times n identity matrix is tr(In)=n\text{tr}(I_n) = n, since there are nn ones on the diagonal. The trace of the zero matrix is 00.
A4×4a1,1a1,2a1,3a1,4a2,1a2,2a2,3a2,4a3,1a3,2a3,3a3,4a4,1a4,2a4,3a4,4
Sweeping the main diagonal

Only the entries on the main diagonal are picked up; everything off it is passed over untouched. That is the entire definition, and it is why the trace is defined for square matrices alone — a non-square matrix has no full diagonal to sweep. Run the sweep on your own matrix on the trace visualizer.

Everything that follows — linearity, the cyclic property, the link to eigenvalues — is a consequence of the trace being this simple a sum.

Trace Notation

Notation

Trace Notation

A three-letter operator that looks like a function and behaves like one, wrapped around a matrix and returning a scalar. The marks worth fixing are its competing spellings, the repeated subscript that picks out the diagonal, and the rearrangement rule that permits exactly one kind of reordering. All of them are catalogued among the linear algebra symbols.
The bracket-and-subscript anatomy [aij][a_{ij}] and the transpose ATA^{T} come from matrix operation notation; det⁡\det and its bars from determinant notation; λ\lambda from eigenvalue notation; Σ\Sigma and its running index from sequence notation.
tr⁡(A)\operatorname{tr}(A)
the trace of A
An operator name, set upright like det⁡\det and rank⁡\operatorname{rank} — the roman type is what marks it as a name rather than a product of three variables t⋅rt\cdot r. It consumes a matrix and returns a scalar, and it is defined only for square matrices, as Definition above states: a rectangular matrix has no diagonal to sum.
Also writtenCapitalised Tr⁡(A)\operatorname{Tr}(A) throughout physics — in quantum mechanics the partial trace Tr⁡B\operatorname{Tr}_B carries a subscript naming the subsystem traced out. German and older Russian texts write sp⁡(A)\operatorname{sp}(A) or Sp⁡(A)\operatorname{Sp}(A), from Spur, the same word English borrowed as "trace". Brackets tr⁡A\operatorname{tr} A without parentheses are common once the argument is a single letter.
Do not confuseThe determinant. Both wrap a square matrix and return one number, and both appear in the characteristic polynomial — but tr⁡\operatorname{tr} is additive and not multiplicative while det⁡\det is multiplicative and not additive, the contrast Linearity below draws out. Neither has a bar notation in common with the other: ∣A∣|A| always means the determinant.
tr⁡(A)=∑i=1naii\operatorname{tr}(A) = \sum_{i=1}^{n} a_{ii}
sum of a-sub-i-i — the entries whose two indices agree
The repeated subscript is the whole definition: in [aij][a_{ij}] the first index is the row and the second the column, so forcing i=ji = j selects exactly the main diagonal. One running letter appears twice in a single symbol, which is a different job from the usual row-and-column pair of matrix notation.
CasesThe same doubled-index device names diagonal entries wherever they matter — aiia_{ii} for the diagonal of a product, δij\delta_{ij} for the identity's entries — and physics compresses the summation sign away entirely under the Einstein convention, where a twice-repeated index is summed by default and aiia_{ii} alone means the trace.
Do not confuseaia_{i} or ai1a_{i1}. A single subscript indexes a vector's component, not a matrix entry; the diagonal needs both slots filled with the same letter, and dropping one silently changes which object is being summed.
tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA)
the trace is unchanged when the factors are rotated, not merely swapped
The permission this notation grants is narrower than it looks. Factors may be rotated — tr⁡(ABC)=tr⁡(BCA)=tr⁡(CAB)\operatorname{tr}(ABC) = \operatorname{tr}(BCA) = \operatorname{tr}(CAB) — because each rotation moves the front factor to the back. The Cyclic Property below works through why.
CasesThe rule is what makes the trace blind to similarity: tr⁡(P−1AP)=tr⁡(APP−1)=tr⁡(A)\operatorname{tr}(P^{-1}AP) = \operatorname{tr}(APP^{-1}) = \operatorname{tr}(A), one rotation and the change of basis cancels — which is why the trace can equal the sum of the eigenvalues at all, a basis-independent quantity read off a basis-dependent array.
Do not confuseFull commutativity. tr⁡(ABC)=tr⁡(BAC)\operatorname{tr}(ABC) = \operatorname{tr}(BAC) is false in general — that is a swap of two adjacent factors, not a rotation. The two look almost identical on the page, and the cyclic rule is routinely over-applied into the wrong one.
⟨A,B⟩F=tr⁡(ATB)\langle A, B\rangle_F = \operatorname{tr}(A^{T}B)
the Frobenius inner product of A and B
The trace borrows the inner-product brackets and the subscript FF names which one: tr⁡(ATB)\operatorname{tr}(A^{T}B) multiplies the two matrices entry by entry and adds, exactly as if each were flattened into a vector of n2n^2 components — Frobenius Inner Product below.
CasesIts norm follows the same pattern one bar-count up, ∥A∥F=tr⁡(ATA)\|A\|_F = \sqrt{\operatorname{tr}(A^{T}A)} — the double-bar norm with a subscript, since a matrix here is being measured as a long vector rather than as a transformation.
Do not confuseThe matrix product itself. tr⁡(ATB)\operatorname{tr}(A^{T}B) is a single number; ATBA^{T}B is a matrix — the trace is what collapses it, and dropping the operator turns a scalar quantity into an array without any visible error.

Linearity

The trace is a linear function from the space of n×nn \times n matrices to the real numbers. It satisfies additivity:

Linearity
tr(A+B)=tr(A)+tr(B)\text{tr}(A + B) = \text{tr}(A) + \text{tr}(B)

and scalar homogeneity:

Linearity
tr(cA)=c⋅tr(A)\text{tr}(cA) = c \cdot \text{tr}(A)

Combined, these give the linearity identity:

Trace Linearity
tr(cA+dB)=c⋅tr(A)+d⋅tr(B)\text{tr}(cA + dB) = c \cdot \text{tr}(A) + d \cdot \text{tr}(B)

for any scalars c,dc, d and any n×nn \times n matrices A,BA, B. Both component properties follow immediately from the definition — the sum of the diagonals of A+BA + B is the sum of the individual diagonal sums, and scaling every entry by cc scales each diagonal entry by cc.

The transpose does not affect the trace, since transposition does not move the diagonal entries:

Trace of Transpose
tr(AT)=tr(A)\text{tr}(A^T) = \text{tr}(A)

It is worth contrasting the trace with the determinant. The determinant is multiplicative (det⁡(AB)=det⁡(A)det⁡(B)\det(AB) = \det(A)\det(B)) but not additive (det⁡(A+B)≠det⁡(A)+det⁡(B)\det(A + B) \neq \det(A) + \det(B) in general). The trace is additive but not multiplicative — tr(AB)\text{tr}(AB) generally has no relation to tr(A)⋅tr(B)\text{tr}(A) \cdot \text{tr}(B). Each captures different structural information about the matrix.
Property Trace Determinant
Additivity tr(A + B) = tr(A) + tr(B) det(A + B) ≠ det(A) + det(B) in general
Multiplicativity tr(AB) has no simple relation to tr(A)·tr(B) det(AB) = det(A) · det(B)
Transpose tr(Aᵀ) = tr(A) det(Aᵀ) = det(A)
Eigenvalue link sum: λ₁ + λ₂ + ⋯ + λₙ product: λ₁ · λ₂ · ⋯ · λₙ
Similarity invariance tr(P⁻¹AP) = tr(A) det(P⁻¹AP) = det(A)

Trace of Special Matrices

For a diagonal matrix D=diag(d1,…,dn)D = \text{diag}(d_1, \dots, d_n), the trace is simply d1+d2+⋯+dnd_1 + d_2 + \cdots + d_n — the entire matrix reduces to its diagonal, and the trace reads off everything. A scalar matrix cIcI has trace cncn.

A skew-symmetric matrix has all diagonal entries equal to zero (since aii=−aiia_{ii} = -a_{ii} forces aii=0a_{ii} = 0), so tr(A)=0\text{tr}(A) = 0 for every real skew-symmetric matrix.

An idempotent matrix — one satisfying A2=AA^2 = A — has a striking property: tr(A)=rank(A)\text{tr}(A) = \text{rank}(A). The eigenvalues of an idempotent matrix are restricted to 00 and 11, the trace counts the number of eigenvalues equal to 11, and this count equals the dimension of the column space.

A nilpotent matrix has all eigenvalues equal to zero, so tr(A)=0\text{tr}(A) = 0. More generally, tr(Ak)=0\text{tr}(A^k) = 0 for every positive integer kk, since the eigenvalues of AkA^k are the kk-th powers of the eigenvalues of AA, and 0k=00^k = 0.

Pitfall: Reading zero trace as singular
Taking tr(A)=0\text{tr}(A) = 0 to mean that AA is singular or nilpotent fails for A=(100−1)A = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}. Its trace is 1+(−1)=01 + (-1) = 0, yet det⁡(A)=−1\det(A) = -1 and A2=IA^2 = I. A zero trace says only that the eigenvalues add up to 00.

Two of these classes land on the same number. Skew-symmetric and nilpotent matrices both have trace 00, the first because its diagonal is forced to vanish entry by entry, the second because its eigenvalues are. In each case the zero is read off from a structural condition that the matrix already satisfies.
Matrix type Defining condition Trace
Diagonal D = diag(d₁,…,dₙ) nonzero entries only on the diagonal d₁ + d₂ + ⋯ + dₙ
Scalar cI every diagonal entry equals c cn
Identity Iₙ diagonal with every diagonal entry equal to 1 n
Skew-symmetric Aᵀ = −A (forces zero diagonal) 0
Idempotent A² = A rank(A)
Nilpotent Aᵏ = O for some k ≥ 1 0

The Cyclic Property

The most distinctive algebraic property of the trace is its invariance under cyclic permutations of a product. For any two matrices AA and BB where both products ABAB and BABA are defined:

Trace Cyclic Property
tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA)

Fact: No other function has this property
Every linear function ff on n×nn \times n matrices with f(AB)=f(BA)f(AB) = f(BA) is a multiple of the trace. Applying the rule to matrices with a single entry 11 forces every off-diagonal entry to count 00 and every diagonal entry to count the same.

Note that ABAB and BABA need not even have the same dimensions — if AA is m×nm \times n and BB is n×mn \times m, then ABAB is m×mm \times m and BABA is n×nn \times n. The traces of these differently-sized matrices are nevertheless equal.

The proof is a direct computation. The (i,i)(i,i) entry of ABAB is ∑kaikbki\sum_k a_{ik} b_{ki}, so tr(AB)=∑i∑kaikbki\text{tr}(AB) = \sum_i \sum_k a_{ik} b_{ki}. The (k,k)(k,k) entry of BABA is ∑ibkiaik\sum_i b_{ki} a_{ik}, so tr(BA)=∑k∑ibkiaik\text{tr}(BA) = \sum_k \sum_i b_{ki} a_{ik}. Both double sums range over the same index pairs and contain the same terms.

For three matrices, the cyclic property extends to

The Cyclic Property
tr(ABC)=tr(BCA)=tr(CAB)\text{tr}(ABC) = \text{tr}(BCA) = \text{tr}(CAB)

Only cyclic reorderings are permitted. The rearrangement tr(ABC)=tr(ACB)\text{tr}(ABC) = \text{tr}(ACB) is false in general — swapping two adjacent factors is not a cyclic permutation.
tr(AB) = tr(BA) even when AB and BA have different sizes120013A (2 × 3)102101B (3 × 2)5224AB (2 × 2)120253013BA (3 × 3)tr(AB) = 5 + 4 = 9tr(BA) = 1 + 5 + 3 = 9different sizes, different entries, the same trace
Two products, one trace

A is 2 × 3 and B is 3 × 2, so both products exist — but AB is a 2 × 2 matrix and BA is a 3 × 3 matrix, with nothing in common entry by entry. Add up each diagonal anyway: 5 + 4 = 9 and 1 + 5 + 3 = 9. Both sums are the same double sum of aijbji, taken in a different order, which is why the trace cannot tell the two products apart.

The same numbers are being added in both traces; only the grouping into diagonal entries differs.

Trace and Eigenvalues

The trace of a matrix equals the sum of its eigenvalues, counted with algebraic multiplicity:

Trace Sum of Eigenvalues
tr(A)=λ1+λ2+⋯+λn\text{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n

This identity connects a trivially computable quantity (add the diagonal entries) to eigenvalue information that ordinarily requires solving a degree-nn polynomial.

The proof comes from the characteristic polynomial p(λ)=det⁡(A−λI)p(\lambda) = \det(A - \lambda I). Expanding this determinant produces a polynomial of degree nn whose leading term is (−λ)n(-\lambda)^n and whose λn−1\lambda^{n-1} coefficient is (−1)n−1tr(A)(-1)^{n-1} \text{tr}(A). By Vieta's formulas, the sum of the roots of pp equals tr(A)\text{tr}(A).

A companion identity links the determinant to the product of eigenvalues: det⁡(A)=λ1λ2⋯λn\det(A) = \lambda_1 \lambda_2 \cdots \lambda_n. Together, the trace and the determinant capture the two simplest symmetric functions of the eigenvalue spectrum — their sum and their product.

Pitfall: Taking diagonal entries as eigenvalues
Reading the eigenvalues of (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} off its diagonal gives 11 and 11. Only the sums agree: the eigenvalues are 33 and −1-1, and 3+(−1)=2=1+13 + (-1) = 2 = 1 + 1.

For a 3×33 \times 3 matrix with eigenvalues 2,−1,42, -1, 4, the trace is 55 and the determinant is −8-8. Neither the trace nor the determinant individually determines the eigenvalues, but together they constrain them heavily. For a 2×22 \times 2 matrix, the trace and determinant determine the eigenvalues completely via the quadratic formula.

Adding the diagonal gives the sum of the eigenvalues without finding a single one of them.

Trace and Similarity

Two matrices AA and BB are similar if B=P−1APB = P^{-1}AP for some invertible matrix PP. Similar matrices represent the same linear transformation in different coordinate systems — PP encodes the change of basis.

The trace is invariant under similarity:

Trace Similarity Invariance
tr(P−1AP)=tr(A)\text{tr}(P^{-1}AP) = \text{tr}(A)

This follows in one step from the cyclic property: tr(P−1AP)=tr(APP−1)=tr(A)\text{tr}(P^{-1}AP) = \text{tr}(APP^{-1}) = \text{tr}(A).

Pitfall: Treating equal traces as similarity
Concluding that matrices with equal traces are similar fails for diag(1,3)\text{diag}(1, 3) and diag(2,2)\text{diag}(2, 2). Both have trace 44, but their eigenvalues 1,31, 3 and 2,22, 2 differ, so they are not similar. Equal trace is necessary, not sufficient.

Invariance under similarity means the trace is a property of the transformation itself, not of any particular matrix representation. No matter which basis is chosen, the trace comes out the same. The eigenvalues share this invariance (similar matrices have the same eigenvalues), and indeed tr(A)=∑λi\text{tr}(A) = \sum \lambda_i is an eigenvalue identity, so trace invariance and eigenvalue invariance are two sides of the same coin.

The determinant is also a similarity invariant: det⁡(P−1AP)=det⁡(A)\det(P^{-1}AP) = \det(A). Together with the trace, it forms the beginning of a sequence of similarity invariants — the coefficients of the characteristic polynomial — that collectively determine the eigenvalue structure of the transformation.

The trace belongs to the linear map, not to its matrix: every choice of basis gives the same number.

The Frobenius Inner Product

The trace provides a natural inner product on the space of n×nn \times n matrices. For two matrices AA and BB, the Frobenius inner product is

Frobenius Inner Product
⟨A,B⟩F=tr(ATB)=∑i=1n∑j=1naijbij\langle A, B \rangle_F = \text{tr}(A^T B) = \sum_{i=1}^{n} \sum_{j=1}^{n} a_{ij} b_{ij}

This is the dot product of AA and BB viewed as vectors of n2n^2 entries. It is symmetric (⟨A,B⟩F=⟨B,A⟩F\langle A, B \rangle_F = \langle B, A \rangle_F), linear in each argument, and positive definite (⟨A,A⟩F>0\langle A, A \rangle_F > 0 whenever A≠OA \neq O).

The associated norm is the Frobenius norm:

Frobenius Norm
∥A∥F=tr(ATA)=∑i,jaij2\|A\|_F = \sqrt{\text{tr}(A^T A)} = \sqrt{\sum_{i,j} a_{ij}^2}

This measures the "total size" of a matrix as the square root of the sum of squares of all entries — the matrix analogue of the Euclidean length of a vector.

The Frobenius inner product turns the space of n×nn \times n matrices into an inner product space, bringing geometric concepts — angles, orthogonality, projections, distances — to bear on matrices themselves, not just on the vectors they act upon.

Trace of Commutators

The commutator of two n×nn \times n matrices is the matrix

Trace of Commutators
[A,B]=AB−BA[A, B] = AB - BA

The commutator measures how far AA and BB are from commuting — it is zero if and only if AB=BAAB = BA.

Regardless of what AA and BB are, the commutator always has trace zero:

Trace of Commutator
tr(AB−BA)=0\text{tr}(AB - BA) = 0

Fact: Possible once matrices are infinite
On polynomials, the derivative DD and the map MM that multiplies by xx satisfy DM−MD=IDM - MD = I, because (xf)′−xf′=f(xf)' - xf' = f. Quantum mechanics' position and momentum obey the same rule up to the constant iℏi\hbar, which is why no finite matrices can represent them.

The cancellation follows from the cyclic property: tr(AB−BA)=tr(AB)−tr(BA)=0\text{tr}(AB - BA) = \text{tr}(AB) - \text{tr}(BA) = 0. This means the identity matrix II can never be a commutator, since tr(I)=n≠0\text{tr}(I) = n \neq 0. In particular, there exist no n×nn \times n matrices A,BA, B satisfying AB−BA=IAB - BA = I when working over the real or complex numbers with finite-dimensional matrices.

The converse also holds, though it is harder: in the space of n×nn \times n matrices over a field, every traceless matrix can in fact be written as a commutator — a result that requires proof beyond the trace identity itself.

The commutators are exactly the matrices with trace zero, so the identity can never be one.

Trace Identities

Several identities involving the trace appear frequently enough to be worth collecting.

If SS is symmetric and KK is skew-symmetric, then their product has trace zero:

Trace Symmetric Skew Zero
S=ST, K=−KT  ⟹  tr(SK)=0S = S^T,\ K = -K^T \implies \text{tr}(SK) = 0

The proof: tr(SK)=tr((SK)T)=tr(KTST)=tr(−KS)=−tr(KS)=−tr(SK)\text{tr}(SK) = \text{tr}((SK)^T) = \text{tr}(K^T S^T) = \text{tr}(-KS) = -\text{tr}(KS) = -\text{tr}(SK), where the last step uses the cyclic property. The only number equal to its own negative is zero.

The trace can be written as a sum of quadratic forms against the standard basis: tr(A)=∑i=1neiTAei\text{tr}(A) = \sum_{i=1}^{n} \mathbf{e}_i^T A \mathbf{e}_i. Each term eiTAei=aii\mathbf{e}_i^T A \mathbf{e}_i = a_{ii} extracts one diagonal entry. This formula generalizes to any orthonormal basis {q1,…,qn}\{\mathbf{q}_1, \dots, \mathbf{q}_n\}:

Trace Orthonormal Basis
tr(A)=∑i=1nqiTAqi\text{tr}(A) = \sum_{i=1}^{n} \mathbf{q}_i^T A \mathbf{q}_i

The result is independent of which orthonormal basis is used — another manifestation of the trace's invariance under orthogonal change of coordinates.

Trace in Differentiation

Many objective functions in optimization and statistics are expressed as traces of matrix products, and computing their gradients requires differentiating with respect to a matrix variable.

The simplest case is the linear function f(X)=tr(AX)f(X) = \text{tr}(AX), where AA is a fixed matrix and XX is the variable. The derivative with respect to XX is

Trace in Differentiation
∂∂Xtr(AX)=AT\frac{\partial}{\partial X} \text{tr}(AX) = A^T

For the quadratic form f(X)=tr(XTAX)f(X) = \text{tr}(X^T A X), the derivative is

Trace in Differentiation
∂∂Xtr(XTAX)=(A+AT)X\frac{\partial}{\partial X} \text{tr}(X^T A X) = (A + A^T)X

When AA is symmetric, this simplifies to 2AX2AX.

Pitfall: Forgetting the transpose in the gradient
Writing ∂∂Xtr(AX)=A\frac{\partial}{\partial X} \text{tr}(AX) = A puts entries in the wrong place. With A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, tr(AX)=x11+2x21+3x12+4x22\text{tr}(AX) = x_{11} + 2x_{21} + 3x_{12} + 4x_{22}, so the derivative in x12x_{12} is 33, the (1,2)(1,2) entry of ATA^T, not of AA.

These formulas are the matrix analogues of the scalar rules ddx(ax)=a\frac{d}{dx}(ax) = a and ddx(ax2)=2ax\frac{d}{dx}(ax^2) = 2ax. They appear in deriving the normal equations for least squares, in the gradient descent updates for matrix factorization problems, and in the analysis of covariance estimators. The trace's linearity and cyclic property make these derivatives clean and systematic — full matrix calculus extends these patterns to products of arbitrary length and composition.

Trace Properties at a Glance

The properties developed across the preceding sections can be collected for quick reference. Each row pairs the defining identity with the structural fact it carries — the trace owes its usefulness to this short list of algebraic guarantees.
Matrix · trace

Trace properties at a glance

Seven identities, each linked to the section that proves it. What holds them together is that the trace sees only the diagonal — every entry below either exploits that or is limited by it.

07properties
Unconditional3
i
Linearity§ 2tr⁡(cA+dB)=ctr⁡(A)+dtr⁡(B)\operatorname{tr}(cA + dB) = c\operatorname{tr}(A) + d\operatorname{tr}(B)
The trace is a linear functional on the space of n × n matrices — it maps matrices to scalars…
Unconditional
Requires
A,BA, B both n×nn \times n

The trace is a linear functional on the space of n×nn \times n matrices — it maps matrices to scalars while respecting addition and scaling. That is a stronger statement than the formula alone: it means the trace lives in the dual space, which is what makes the Frobenius inner product possible.

ii
Transpose invariance§ 9tr⁡(AT)=tr⁡(A)\operatorname{tr}(A^{\mathsf{T}}) = \operatorname{tr}(A)
Transposition reflects entries across the main diagonal, and the diagonal entries are exactly…
Unconditional
Requires
AA square

Transposition reflects entries across the main diagonal, and the diagonal entries are exactly the ones fixed by that reflection. Since the trace reads only those, it cannot notice.

vi
Commutator trace§ 8tr⁡(AB−BA)=0\operatorname{tr}(AB - BA) = 0
Immediate from the cyclic property and linearity.
Unconditional
Requires
A,BA, B both n×nn \times n

Immediate from the cyclic property and linearity. The consequence is sharper than it looks: since tr⁡(In)=n≠0\operatorname{tr}(I_n) = n \neq 0 over R\mathbb{R} or C\mathbb{C}, the identity matrix is never a commutator. No pair of matrices satisfies AB−BA=IAB - BA = I in finite dimensions — which is exactly why the canonical commutation relation of quantum mechanics needs infinite-dimensional operators.

Conditional4
iii
Cyclic property§ 4tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA)
Rotating the factors is allowed; permuting them arbitrarily is not.
Conditional
Holds when
both products defined — AA and BB need not be square
Common error
reading it as full commutativity: tr⁡(ABC)=tr⁡(BCA)\operatorname{tr}(ABC) = \operatorname{tr}(BCA) but not tr⁡(BAC)\operatorname{tr}(BAC)

Rotating the factors is allowed; permuting them arbitrarily is not. For three matrices the cyclic rotations ABC→BCA→CABABC \to BCA \to CAB all share a trace, while BACBAC generally does not. This is the identity everything below is derived from — it is the reason the trace survives a change of basis at all.

Where it breaksA = [[1, 0], [0, 0]], B = [[0, 1], [0, 0]], C = [[0, 0], [1, 0]]
tr(ABC) = 1 but tr(BAC) = 0
iv
Similarity invariance§ 6tr⁡(P−1AP)=tr⁡(A)\operatorname{tr}(P^{-1}AP) = \operatorname{tr}(A)
A direct consequence of the cyclic property: rotate P^-1 to the back and it meets P.
Conditional
Holds when
PP invertible

A direct consequence of the cyclic property: rotate P−1P^{-1} to the back and it meets PP. The consequence is what matters — the trace is a property of the underlying linear transformation, not of the basis chosen to write it down. Two matrices with different traces cannot represent the same map.

v
Eigenvalue sum§ 5tr⁡(A)=λ1+λ2+⋯+λn\operatorname{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n
Spectral information read straight off the diagonal, with no characteristic polynomial to solve.
Conditional
Holds when
eigenvalues counted with algebraic multiplicity, over C\mathbb{C}

Spectral information read straight off the diagonal, with no characteristic polynomial to solve. Over R\mathbb{R} the statement can fail because some eigenvalues may not exist there — a rotation matrix with θ≠0,π\theta \neq 0, \pi has trace 2cos⁡θ2\cos\theta and no real eigenvalues at all. The sum is still correct once the complex pair is counted.

vii
Frobenius inner product§ 7⟨A,B⟩F=tr⁡(ATB)\langle A, B \rangle_F = \operatorname{tr}(A^{\mathsf{T}}B)
Gives the space of matrices a geometry — angles, lengths and projections, exactly as the dot…
Conditional
Holds when
real entries; use A∗A^* for the complex case

Gives the space of matrices a geometry — angles, lengths and projections, exactly as the dot product does for vectors. Positive definiteness holds because ⟨A,A⟩F\langle A, A \rangle_F is the sum of every entry squared, so the induced norm is the Frobenius norm.

Unconditional
Conditional
Linearity§ 2Unconditional
tr⁡(cA+dB)=ctr⁡(A)+dtr⁡(B)\operatorname{tr}(cA + dB) = c\operatorname{tr}(A) + d\operatorname{tr}(B)
Requires
A,BA, B both n×nn \times n
The trace is a linear functional on the space of n×nn \times n matrices — it maps matrices to scalars while respecting addition and scaling. That is a stronger statement than the formula alone: it means the trace lives in the dual space, which is what makes the Frobenius inner product possible.
Read the full section
tr⁡(AT)=tr⁡(A)\operatorname{tr}(A^{\mathsf{T}}) = \operatorname{tr}(A)
Requires
AA square
Transposition reflects entries across the main diagonal, and the diagonal entries are exactly the ones fixed by that reflection. Since the trace reads only those, it cannot notice.
Read the full section
tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA)
Holds when
both products defined — AA and BB need not be square
Common error
reading it as full commutativity: tr⁡(ABC)=tr⁡(BCA)\operatorname{tr}(ABC) = \operatorname{tr}(BCA) but not tr⁡(BAC)\operatorname{tr}(BAC)
Rotating the factors is allowed; permuting them arbitrarily is not. For three matrices the cyclic rotations ABC→BCA→CABABC \to BCA \to CAB all share a trace, while BACBAC generally does not. This is the identity everything below is derived from — it is the reason the trace survives a change of basis at all.
Where it breaksA = [[1, 0], [0, 0]], B = [[0, 1], [0, 0]], C = [[0, 0], [1, 0]]
tr(ABC) = 1 but tr(BAC) = 0
Read the full section
tr⁡(P−1AP)=tr⁡(A)\operatorname{tr}(P^{-1}AP) = \operatorname{tr}(A)
Holds when
PP invertible
A direct consequence of the cyclic property: rotate P−1P^{-1} to the back and it meets PP. The consequence is what matters — the trace is a property of the underlying linear transformation, not of the basis chosen to write it down. Two matrices with different traces cannot represent the same map.
Read the full section
tr⁡(A)=λ1+λ2+⋯+λn\operatorname{tr}(A) = \lambda_1 + \lambda_2 + \cdots + \lambda_n
Holds when
eigenvalues counted with algebraic multiplicity, over C\mathbb{C}
Spectral information read straight off the diagonal, with no characteristic polynomial to solve. Over R\mathbb{R} the statement can fail because some eigenvalues may not exist there — a rotation matrix with θ≠0,π\theta \neq 0, \pi has trace 2cos⁡θ2\cos\theta and no real eigenvalues at all. The sum is still correct once the complex pair is counted.
Read the full section
tr⁡(AB−BA)=0\operatorname{tr}(AB - BA) = 0
Requires
A,BA, B both n×nn \times n
Immediate from the cyclic property and linearity. The consequence is sharper than it looks: since tr⁡(In)=n≠0\operatorname{tr}(I_n) = n \neq 0 over R\mathbb{R} or C\mathbb{C}, the identity matrix is never a commutator. No pair of matrices satisfies AB−BA=IAB - BA = I in finite dimensions — which is exactly why the canonical commutation relation of quantum mechanics needs infinite-dimensional operators.
Read the full section
⟨A,B⟩F=tr⁡(ATB)\langle A, B \rangle_F = \operatorname{tr}(A^{\mathsf{T}}B)
Holds when
real entries; use A∗A^* for the complex case
Gives the space of matrices a geometry — angles, lengths and projections, exactly as the dot product does for vectors. Positive definiteness holds because ⟨A,A⟩F\langle A, A \rangle_F is the sum of every entry squared, so the induced norm is the Frobenius norm.
Read the full section
Two of these are load-bearing for the rest. Linearity makes the trace a functional rather than merely a formula, and the cyclic property is what similarity invariance, the eigenvalue sum and the commutator identity are all derived from.
Trace properties at a glance·/linear-algebra/matrix/traceLearn Math Class

Common Pitfalls

Six mistakes account for many wrong answers about the trace. Four are marked with a box where they happen in the sections above. The other two, multiplying traces and swapping factors inside a trace, are flagged in the text of the linearity and cyclic property sections. Here each is worked through in full, with the wrong and the right working side by side.

Multiplying traces

The trace of a product is computed as the product of the traces, the way the determinant of a product is.

Wrong working: with A=(1201)A = \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix} and B=(1031)B = \begin{pmatrix} 1 & 0 \\ 3 & 1 \end{pmatrix},
tr(AB)=tr(A)⋅tr(B)=2⋅2=4\text{tr}(AB) = \text{tr}(A) \cdot \text{tr}(B) = 2 \cdot 2 = 4


Right working: multiply first, then add the diagonal.
AB=(7231),tr(AB)=7+1=8AB = \begin{pmatrix} 7 & 2 \\ 3 & 1 \end{pmatrix}, \quad \text{tr}(AB) = 7 + 1 = 8


Why it happens: det⁡(AB)=det⁡(A)det⁡(B)\det(AB) = \det(A)\det(B) holds, and the trace and the determinant are learned side by side as the two numbers attached to a square matrix.

How to check: the diagonal entries of ABAB use the off-diagonal entries of AA and BB, which tr(A)\text{tr}(A) and tr(B)\text{tr}(B) never see. With A=B=(0110)A = B = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, both traces are 00, yet AB=IAB = I has trace 22.

Reading zero trace as singular

A matrix with trace 00 is taken to be singular or nilpotent. The statements of the special-matrices section are read backwards, or the trace is confused with the determinant.

Wrong working: A=(100−1)A = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} has tr(A)=1+(−1)=0\text{tr}(A) = 1 + (-1) = 0, so AA is singular, and some power of AA is the zero matrix.

Right working: det⁡(A)=(1)(−1)−0=−1≠0\det(A) = (1)(-1) - 0 = -1 \neq 0, so AA is invertible; in fact A−1=AA^{-1} = A. Its square is A2=IA^2 = I, so no power of AA is zero. The eigenvalues are 11 and −1-1, and the only thing the zero trace records is that they add up to 00.

Why it happens: a nilpotent matrix does have trace 00, and a single zero number is how singularity is usually detected, through the determinant.

How to check: compute the determinant to test singularity. For nilpotence of a 2×22 \times 2 matrix, compute A2A^2, which must be the zero matrix.

Swapping factors inside a trace

The cyclic property is applied as if the trace let the factors of a product be reordered in any way.

Wrong working: with A=(1000)A = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, B=(0100)B = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} and C=(0010)C = \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}, tr(ACB)=tr(ABC)\text{tr}(ACB) = \text{tr}(ABC).

Right working: compute both.
ABC=(1000),ACB=(0000)ABC = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, \quad ACB = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}

so tr(ABC)=1\text{tr}(ABC) = 1 and tr(ACB)=0\text{tr}(ACB) = 0. The rotations do agree: BCA=(1000)BCA = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} and CAB=(0001)CAB = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix} both have trace 11.

Why it happens: with two factors, tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA), and every reordering of two factors is a rotation. The rule looks like commutativity and is carried over to three factors.

How to check: write the factors around a circle. A permitted reordering reads the same circle from a different starting point; ACBACB reads ABCABC in the opposite direction.

Taking diagonal entries as eigenvalues

Because the trace is both the sum of the diagonal entries and the sum of the eigenvalues, the diagonal entries are taken to be the eigenvalues.

Wrong working: A=(1221)A = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} has diagonal entries 11 and 11, so its eigenvalues are 11 and 11.

Right working: solve the characteristic equation.
det⁡(A−λI)=(1−λ)2−4=0  ⟹  λ=3 or λ=−1\det(A - \lambda I) = (1 - \lambda)^2 - 4 = 0 \implies \lambda = 3 \text{ or } \lambda = -1

The sums agree, 3+(−1)=2=1+13 + (-1) = 2 = 1 + 1, but the individual values do not.

Why it happens: for diagonal and triangular matrices the diagonal entries really are the eigenvalues, and the trace identity looks like the same statement for every matrix.

How to check: the product of the eigenvalues must equal the determinant. Here det⁡(A)=1−4=−3\det(A) = 1 - 4 = -3, which matches 3⋅(−1)3 \cdot (-1) but not 1⋅11 \cdot 1.

Treating equal traces as similarity

Two matrices with the same trace are declared similar, by reading the similarity invariance of the trace in reverse.

Wrong working: diag(1,3)\text{diag}(1, 3) and diag(2,2)\text{diag}(2, 2) both have trace 44, so they are similar.

Right working: diag(2,2)=2I\text{diag}(2, 2) = 2I, and P−1(2I)P=2IP^{-1}(2I)P = 2I for every invertible PP, so 2I2I is similar only to itself. It is not similar to diag(1,3)\text{diag}(1, 3); their eigenvalues 2,22, 2 and 1,31, 3 differ.

Why it happens: the invariance statement says that similar matrices have equal traces. The reverse direction sounds equally natural but does not follow.

How to check: compare other similarity invariants. Here the determinants are 33 and 44, so the matrices cannot be similar. Even equal trace and equal determinant are not enough: II and (1101)\begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} share trace 22 and determinant 11, and are not similar.

Forgetting the transpose in the gradient

The derivative of tr(AX)\text{tr}(AX) with respect to XX is taken to be AA, by direct analogy with ddx(ax)=a\frac{d}{dx}(ax) = a.

Wrong working: ∂∂Xtr(AX)=A\frac{\partial}{\partial X} \text{tr}(AX) = A.

Right working: tr(AX)=∑i∑jaijxji\text{tr}(AX) = \sum_{i} \sum_{j} a_{ij} x_{ji}, so the derivative with respect to xjix_{ji} is aija_{ij}. The entry in position (j,i)(j, i) of the gradient is aija_{ij}, which makes the gradient ATA^T. With A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix},
tr(AX)=x11+2x21+3x12+4x22,∂∂Xtr(AX)=(1324)=AT\text{tr}(AX) = x_{11} + 2x_{21} + 3x_{12} + 4x_{22}, \quad \frac{\partial}{\partial X} \text{tr}(AX) = \begin{pmatrix} 1 & 3 \\ 2 & 4 \end{pmatrix} = A^T


Why it happens: the scalar rule has no transpose to forget, and for a symmetric AA the two answers coincide, so the slip often goes unnoticed.

How to check: expand tr(AX)\text{tr}(AX) for a 2×22 \times 2 case and place the coefficient of each xijx_{ij} in position (i,j)(i, j) of the gradient.

Matrix Trace FAQ

Is tr⁡(ABC)\operatorname{tr}(ABC) the same as tr⁡(BAC)\operatorname{tr}(BAC)?

+
No, and this is the most over-applied rule on the topic. The cyclic property permits rotation only, moving the front factor to the back: tr⁡(ABC)=tr⁡(BCA)=tr⁡(CAB)\operatorname{tr}(ABC) = \operatorname{tr}(BCA) = \operatorname{tr}(CAB). Swapping two adjacent factors, as BACBAC does, is a different move and generally changes the value. The two forms look almost identical written down.Read more →

Is tr⁡(ATB)\operatorname{tr}(A^{T}B) a number or a matrix?

+
A number. The product ATBA^{T}B is itself a matrix, and the trace is exactly what collapses it to a single scalar by summing the diagonal. Dropping the operator turns a scalar quantity into an array with nothing visibly wrong on the page, which makes it an easy error to carry through a derivation unnoticed.Read more →

Why is tr⁡\operatorname{tr} set in upright type rather than italics?

+
The roman type marks it as an operator name rather than a product of two variables tt and rr, the same convention that sets det⁡\det and rank⁡\operatorname{rank} upright. Spellings vary by field: physics capitalises it as Tr⁡\operatorname{Tr}, while German and older Russian texts write sp⁡\operatorname{sp}, from the word Spur.Read more →