Typical situations in which a density matrix is needed include: a quantum system in thermal equilibrium (at finite temperatures), nonequilibrium time-evolution that starts out of a mixed equilibrium state, and entanglement between two subsystems, where each individual system must be described by a density matrix even though the complete system may be in a pure state.

The density matrix (commonly designated by ρ) is an operator acting on the Hilbert
space of the system in question. For the special case
of a pure state, it is given by the projection operator of this
state. For a mixed state, where the system is in the
quantum-mechanical state |ψ_{j}⟩ with probability p_{j},
the density matrix is the sum of the projectors, weighted
with the appropriate probabilities (see bra-ket notation):

ρ = ∑_{j} p_{j} |ψ_{j}⟩⟨ψ_{j}|

The density matrix is used to calculate the expectation
value of any operator A of the system, averaged over the
different states |ψ_{j}⟩. This is done by taking the
trace of the product of ρ and A:

tr[ρ A]=∑_{j} p_{j} ⟨ψ_{j}|A|ψ_{j}⟩

The probabilities p_{j} are nonnegative and normalized (i.e.
their sum gives one). For the density matrix, this means
that ρ is a positive semidefinite hermitian operator (its eigenvalues are nonnegative) and the trace of ρ
(the sum of its eigenvalues) is equal to one.