The Ergodic Theorem for Markov Chains
Suppose a frog hops between lily pads forever. It chooses its next pad at random, following fixed transition probabilities. Now watch this frog for a very long time. Record the fraction of time it spends on each pad. Does that fraction settle down to a definite number? And if it does, is that number the same as the long-run probability predicted by the chain's Stationary Distributions? The Ergodic Theorem for Markov Chains answers both questions with a resounding yes. This holds under hypotheses that are both natural and necessary — irreducibility and positive recurrence. This result is the workhorse behind an enormous amount of applied probability. It is the reason Monte Carlo Markov Chain (MCMC) methods work. It is the reason PageRank converges to a sensible ranking of web pages. It is also the reason queueing systems and genetic drift models can be analyzed through simple long-run averages, instead of intractable finite-time computations. It converts a spatial object — the stationary distribution , defined by solving a system of linear equations — into a temporal statement about a single simulated trajectory. This identification of time averages with space averages is the defining feature of ergodicity. This concept echoes throughout dynamical systems, statistical mechanics, and information theory. The big picture is this: an irreducible, positive recurrent Markov chain has a unique stationary distribution . Regardless of where the chain starts, the long-run fraction of time spent in each state converges almost surely to . This is fundamentally a strong law of large numbers. However, it is proved via a probabilistic renewal argument rather than classical independence. Successive visits to a state are not literally independent. Instead, they are governed by a renewal structure induced by Periodicity and Positive Recurrence visits to a fixed reference state. This article states the theorem with full hypotheses. It gives a complete proof using the renewal-reward method. It distinguishes the theorem sharply from the separate (and stronger) fact of distributional convergence to , which additionally requires aperiodicity. It also works through two concrete asymmetric chains by hand. It closes by placing the theorem in its historical context. Finally, it surveys its use in modern computation, setting the stage for its most famous application domain: Random Walks.
- The Ergodic Theorem says: for an irreducible, positive recurrent chain, long-run time averages equal the stationary distribution , almost surely, from any starting state.
- It is proved via a renewal argument: successive excursions between visits to a fixed state are i.i.d., so the ordinary strong law of large numbers applies to excursion lengths and rewards.
- It does not require aperiodicity — that is only needed for the separate, stronger statement that .
- The proof yields a bonus: the ratio limit theorem, for any bounded function , generalizing the time-average statement.
- Positive recurrence is essential: null recurrent or transient chains have no stationary probability distribution, and time averages of every state vanish.
- Key idea: long-run time spent per state equals stationary probability, because both equal (mean return time), and this equality is forced by a strong law of large numbers applied to i.i.d. excursion lengths.
Where this lives today
The Ergodic Theorem is the theoretical foundation of Markov Chain Monte Carlo (MCMC) methods, including the Metropolis–Hastings algorithm and Gibbs sampling used throughout Bayesian statistics: to estimate an expectation under a complicated target distribution , one constructs an ergodic chain whose stationary distribution is and then uses the time average as an estimator, justified exactly by part (3) of the theorem. In web search, Google's original PageRank algorithm models a web surfer as an ergodic Markov chain on the graph of hyperlinks; the stationary distribution (equivalently the long-run fraction of time the surfer spends on each page) is the page's rank. In statistical physics, the theorem underlies the equivalence of time averages and ensemble (phase-space) averages for systems governed by ergodic Markov dynamics, an analogue of the ergodic hypothesis in classical mechanics. In queueing theory and operations research, long-run fractions of time a server is busy or a buffer is at a given occupancy are computed via using this theorem, informing capacity planning. In genetics, the theorem justifies computing long-run allele-frequency behavior under Markov models of genetic drift and mutation–selection balance. In computer science and cryptography, mixing-time analysis (bounding how fast approaches ) builds on top of the ergodic theorem's guarantee that convergence happens at all, before quantifying its rate — a topic that connects directly to the study of Random Walks on graphs and groups, where explicit rates of convergence to are a central object of study.
Ask the tutor: How does adding aperiodicity upgrade this theorem into the stronger statement that for every pair of states?
Let be a time-homogeneous Markov chain on a countable state space with transition matrix , .
Irreducibility. The chain is irreducible if for all there exists with , i.e., every state is reachable from every other state.
Recurrence and positive recurrence. State is recurrent if . Let be the first return time to (starting from ), and let be its mean. A recurrent state is positive recurrent if , and null recurrent if . In an irreducible chain, positive recurrence is a class property: either all states are positive recurrent or none are.
Ergodic chain. An irreducible, positive recurrent, discrete-time Markov chain is called ergodic in this context (some authors reserve "ergodic" for the additional hypothesis of aperiodicity — this article follows the convention, standard in Ross and Grimmett–Stirzaker, that ergodic means irreducible + positive recurrent, flagging where aperiodicity is separately required).
Stationary distribution. A probability distribution on is stationary for if
Time average. For a realization of the chain and a state , define the (random) long-run fraction of time spent in up to time :
and the time average
when this limit exists. The Ergodic Theorem asserts that for an irreducible positive recurrent chain, exists almost surely, is a.s. constant, equals , and equals the unique stationary probability — regardless of the initial distribution of .
Intuition
Picture the chain as a train that returns again and again to a home station . Each time it leaves and comes back, it completes one excursion — a self-contained probabilistic experiment whose statistics (how long the excursion lasts, how much time within it was spent at any particular state ) depend only on the transition matrix , not on the calendar time at which the excursion started. Because the future of the chain after each return to depends only on being at — the Markov property — these excursions are independent and identically distributed. This is the entire engine of the proof: convert a dependent stochastic process into an i.i.d. sequence of excursions, then unleash the ordinary strong law of large numbers. Once you have i.i.d. excursions, two numbers control everything: the mean excursion length , and the mean number of visits to per excursion, . The long-run fraction of time in is (visits to per excursion)/(length of excursion), and a renewal-reward computation shows this ratio is exactly , with as the special case . The remarkable content of the theorem is that this ratio, built from renewal statistics, coincides precisely with the linear-algebraic object obtained by solving . The figure below shows a -state chain and a single simulated trajectory's histogram of time spent in each state, converging toward the bars predicted by .
Central theorem
Let be an irreducible, positive recurrent Markov chain on a countable state space with transition matrix , started from an arbitrary initial state or initial distribution. Then: 1. There is a unique stationary distribution on , given by
2. For every state , almost surely,
where is the number of visits to in the first steps, and the convergence holds regardless of the distribution of . 3. More generally, for any bounded function ,
Proof technique: renewal-reward theory applied to excursions between visits to a fixed reference state, combined with the classical Strong Law of Large Numbers (SLLN). Fix a reference state . By irreducibility, from any starting distribution the chain reaches in finite time almost surely (standard fact for irreducible countable chains: since communicates with every state, and the state space is countable, the chain visits eventually with probability 1 — this uses only irreducibility and does not require positive recurrence). So without loss of generality we may assume the chain starts at ; the finitely many initial steps before the first visit to do not affect any of the a.s. limits below, since dividing by washes out any fixed finite prefix.
Step 1: Construct i.i.d. excursions. Define the successive return times to :
By recurrence of (which holds since the chain is positive recurrent, a fortiori recurrent), each is finite almost surely, and the chain returns to infinitely often a.s. Define the -th excursion as the block of random variables
and its length . By the strong Markov property applied at the stopping times (each of which is a stopping time since the event depends only on ), the process after time , started at , is a probabilistic copy of the whole chain started afresh at , independent of everything that happened before time . Consequently the excursions are i.i.d. random elements (as sequences), and in particular the lengths are i.i.d. with
By positive recurrence, .
Step 2: Reward structure for visits to a state . For each excursion , define the "reward"
the number of visits to strictly within the -th excursion (using the half-open convention so successive excursions partition the time axis without double-counting the shared endpoint ). Since are i.i.d., so are , with common mean
finite because and (a nonnegative random variable bounded above in expectation by a finite number has finite expectation).
Step 3: Apply the SLLN to excursion lengths and rewards. Since are i.i.d. with finite mean , the classical Kolmogorov Strong Law of Large Numbers gives
Note , the time of the -th return. So
Similarly, since are i.i.d. with finite mean , the SLLN gives
Note that counts the number of visits to up to time , i.e. .
Step 4: Sandwich to convert renewal-indexed convergence to time-indexed convergence. Because the chain visits infinitely often a.s., for every there is (a.s., for large) a unique with , and as . Since is nondecreasing,
Divide through by and use :
Write the left side as
more directly: using and along the (a.s. infinite) subsequence ,
all almost surely (as a.s.). Multiplying/dividing these a.s. limits (all nondegenerate, positive, finite constants) shows both the lower and upper bounds on converge to the same limit
By the squeeze theorem, almost surely,
Step 5: Identify the limit with . Set for each . First check is a probability distribution: summing over counts every one of the steps of a single excursion exactly once (since every visited state , , is some state ), so
Also for all . Taking : every excursion visits exactly once in (at its start), so and , matching the claimed formula at ; since was an arbitrary state, this gives for every (applying the whole argument with reference state in place of and reading off directly, or by the stationarity argument below combined with uniqueness). Next, show is stationary, i.e., . This is the standard renewal/occupation-measure computation: consider . By definition,
so, using the Markov property to write (valid because is determined by , so conditioning on and , the next step's transition still uses row of ),
For : the events for equal (since ), so the sum equals exactly by definition (re-indexing vs. costs nothing since the term as ). For : the sum is (the only with and is , by definition of as the first return). In both cases,
Dividing by gives for all , i.e. : is stationary.
Step 6: Uniqueness of the stationary distribution. Suppose is any stationary distribution. By induction, for all . Consider — since and is stationary, for every , so
But is a bounded () sequence converging a.s. (by Step 4, valid started from any state, hence from by conditioning) to the constant ; by the Bounded Convergence Theorem, . Comparing the two, for every . Hence the stationary distribution is unique and equals the constructed above. This proves part (1) and finishes the almost-sure convergence claim of part (2), where "regardless of the initial distribution" follows because Step 4's argument only used that the chain a.s. reaches eventually (guaranteed by irreducibility from any start) and is thereafter a copy of the chain started at .
Step 7: Extend to bounded functions (part 3). Let be bounded, . For finite , or more generally when (automatic if is bounded, since ),
If is finite this is a finite sum of terms each converging a.s. by part (2), so the whole sum converges a.s. to . If is countably infinite, fix and choose a finite set with (possible since is a probability measure); one shows, using -type renewal bounds uniformly summable over (justified because as , an immediate consequence of and dominated convergence for the series), that the tail contribution is a.s. eventually bounded by , while the finite part converges exactly as in the finite case; letting gives the general result.
∎Worked examples
Example 1 (three-state chain, asymmetric transition probabilities). Let with transition matrix (rows )
This matches the diagram above (with the arrow labels : , : , : , : , : , : ). It is irreducible (every state reachable from every other in steps: , , etc.) and, being a finite irreducible chain, automatically positive recurrent (a standard consequence: a finite irreducible chain cannot be null recurrent or transient, since some state must be visited infinitely often by pigeonhole, forcing recurrence, and finite mean return time follows from finiteness of the state space via the same occupation-measure argument used in the theorem's Step 6). Solve , :
From the second equation, . Substitute into the first:
so , giving . Substitute into . Normalize: , so
Check normalization: ✓. Check stationarity of directly: ✓. By the Ergodic Theorem, no matter whether the frog starts at , , or , its long-run fraction of hops landing on converges almost surely to , and the mean return time to is steps.
Example 2 (a birth–death chain on with reflecting boundaries, asymmetric rates). Let with (reflecting at ), , for , and (reflecting at ). This chain is irreducible (a path connects any two states) and finite, hence ergodic (positive recurrent). Detailed balance holds for birth–death chains: (this is a standard shortcut, but let us not assume it and instead verify directly to keep the example self-contained and honest about hypotheses). Guess via detailed balance: . Next . Next . Normalize: , so , and
Verify detailed balance implies global balance (a fact that must be checked, not assumed, though it is standard for birth-death chains): for state , in-flow ✓ matching out-flow trivially since is exactly this quantity by construction. A direct check of the full balance equation at state : ✓, confirming stationarity. The Ergodic Theorem now guarantees: starting from any state, e.g. , the long-run proportion of time the chain spends at state converges almost surely to , and the mean recurrence time to state is steps.
Consider simple symmetric random walk on : for every . This chain is irreducible (every integer reachable from every other) and it is a classical fact (a special case of results about Random Walks) that it is recurrent — the walk returns to with probability — but null recurrent: . Because there is no finite mean return time, the entire renewal-reward argument in the theorem's proof collapses at Step 3: the Strong Law of Large Numbers still says a.s. (an SLLN for i.i.d. nonnegative variables with infinite mean does hold, sending the average to infinity), which forces, by the same squeeze argument, for every state . Indeed one can show directly a.s. for every fixed on : the chain spends a vanishing fraction of time at any single site as , consistent with there being no stationary probability distribution at all (the only nonnegative solution to with , up to constant scaling, is not summable to over ). This shows precisely what positive recurrence buys us: without it, the "space average" does not exist as a probability distribution, and the "time average" degenerates to zero at every state rather than converging to a meaningful positive number. The conclusion of the theorem genuinely requires the hypothesis , not merely recurrence.
Scope, edge cases & common traps
| Situation | What holds | What fails / must not be assumed |
|---|---|---|
| Irreducible, positive recurrent (finite or countable ) | Unique ; a.s., any start | — |
| Irreducible, positive recurrent, periodic | Time averages still converge to | fails (e.g. period 2 chain: oscillates) |
| Irreducible, null recurrent | No stationary probability distribution exists | Time average of every state is , not |
| Irreducible, transient | Chain a.s. leaves every finite set eventually | No stationary distribution; occupation counts stay a.s. finite (bounded), not |
| Reducible chain | Ergodic theorem applies within each closed communicating class separately | Global time average depends on which class is absorbed into; no single governs the whole space |
| Finite state space, irreducible | Positive recurrence is automatic | Common trap: forgetting to verify irreducibility (a finite chain can still be reducible) |
The mathematician behind it
Origins · 1 minAndrei Andreyevich Markov and how this was discovered
Markov introduced the chains that bear his name in 1906, initially to settle a dispute about whether the Law of Large Numbers requires independence (he showed dependent sequences with the "Markov property" could still obey averaging laws), applying his early chains famously to the alternation of vowels and consonants in Pushkin's Eugene Onegin. He was a student of Pafnuty Chebyshev and a rigorous, combative figure in Russian mathematics, known equally for his work on inequalities and continued fractions.
Does the Ergodic Theorem require the chain to be aperiodic?
No. The theorem as stated — that time averages converge almost surely to — requires only irreducibility and positive recurrence. Aperiodicity is a separate, additional hypothesis needed only for the different (stronger, pointwise) claim that as for each fixed pair of states. A periodic chain, such as one alternating deterministically between two states, still satisfies the time-average convergence (each state is visited exactly half the time in the long run), even though its -step transition probabilities oscillate forever and never converge to a single limit. Conflating these two statements is the most common error students make when applying this theorem, so always check which convergence mode a problem is actually asking about.
Why is the proof done via renewal theory rather than a direct martingale or spectral argument?
The renewal (excursion) approach is the most elementary route requiring the least additional machinery: it uses only the strong Markov property (to get i.i.d. excursions) and the ordinary Strong Law of Large Numbers, both of which are typically already available once one has developed Stationary Distributions and recurrence theory. Spectral arguments (diagonalizing ) require finite or at least well-behaved countable state spaces and extra assumptions like reversibility or diagonalizability, so they are less general. Martingale arguments exist but typically reprove the same excursion structure in different notation. The renewal method is also illuminating: it makes transparent why , an identity that spectral methods obscure.
Is the limit in the theorem random, or a fixed number?
It is a fixed, non-random number — this is part of the content of the Strong Law of Large Numbers applied in the proof. Although each finite trajectory of the chain is random, and itself is a random variable for each fixed , the limiting ratio converges, with probability , to the deterministic constant that depends only on the transition matrix (via ), not on the particular random path realized. This is exactly analogous to how the sample average of i.i.d. fair coin flips converges a.s. to the fixed constant , not to some random limit.
Does the starting distribution of affect the long-run time average?
No — this is one of the theorem's most powerful features. Regardless of whether is deterministic (a fixed state) or has an arbitrary initial distribution, and regardless of what that distribution is, the almost-sure limit of is always . The proof shows this because, by irreducibility, the chain a.s. reaches the reference state in finite time from any start, and the excursion structure used afterward depends only on being at , discarding all memory of . Only the finite prefix before the first hit of differs across starting distributions, and finite prefixes vanish upon dividing by .
What happens if the state space is infinite but the chain is only recurrent, not positive recurrent?
Then the chain is null recurrent: it returns to every state with probability , but the mean return time is infinite. In this case no stationary probability distribution exists (any nonnegative solution to that is unique up to scaling fails to be summable to a finite total mass), and the conclusion of the theorem fails in the strongest possible way: the time average converges almost surely to for every state , rather than to a positive stationary probability. The simple symmetric random walk on is the canonical example, discussed in the counterexample above, and this phenomenon reappears throughout the study of Random Walks in one and two dimensions.
How does this theorem relate to the general "ergodic theorem" in dynamical systems (e.g. Birkhoff's theorem)?
They are close cousins under a shared name. Birkhoff's Ergodic Theorem, from measure-preserving dynamical systems, says that for an ergodic measure-preserving transformation on a probability space, time averages converge a.s. to the space average . The Markov chain version here is a special case: run the chain on the (typically infinite) path space with the shift map as and the law of the stationary chain as ; irreducibility and positive recurrence together imply is ergodic in the dynamical-systems sense with respect to the stationary law. So this theorem can be seen as Birkhoff's theorem specialized to Markov shifts, though the renewal-theoretic proof given here is self-contained and does not require invoking the general Birkhoff theorem as machinery.
Can the theorem be extended to continuous-time Markov chains?
Yes, with the natural modifications: for an irreducible, positive recurrent continuous-time chain, the long-run fraction of time (measured in continuous clock time, not number of jumps) spent in state converges almost surely to , where solves the stationary equations for the generator matrix (i.e. ), weighted appropriately by the holding-time rates at each state. The proof again uses an excursion/renewal decomposition between visits to a reference state, now tracking sojourn times rather than discrete step counts, and is essentially the same argument dressed in continuous-time notation.