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 π\pi, 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 π\pi. Regardless of where the chain starts, the long-run fraction of time spent in each state jj converges almost surely to π(j)\pi(j). 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 π\pi, 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.

Key takeaways
  • The Ergodic Theorem says: for an irreducible, positive recurrent chain, long-run time averages equal the stationary distribution π\pi, 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 Pn(i,j)→π(j)P^n(i,j) \to \pi(j).
  • The proof yields a bonus: the ratio limit theorem, 1n∑k=1nf(Xk)→∑jπ(j)f(j)\frac{1}{n}\sum_{k=1}^n f(X_k) \to \sum_j \pi(j) f(j) for any bounded function ff, 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)−1^{-1}, 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 Eπ[f]\mathbb{E}_\pi[f] under a complicated target distribution π\pi, one constructs an ergodic chain whose stationary distribution is π\pi and then uses the time average 1n∑f(Xk)\frac{1}{n}\sum f(X_k) 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 π\pi (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 π\pi 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 Pn(i,⋅)P^n(i,\cdot) approaches π\pi) 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 π\pi are a central object of study.

Ask the tutor: How does adding aperiodicity upgrade this theorem into the stronger statement that Pn(i,j)→π(j)P^n(i,j) \to \pi(j) for every pair of states?

DefinitionErgodic Markov chain, time averages, and the objects in the theorem

Let X=(Xn)n≥0X = (X_n)_{n \ge 0} be a time-homogeneous Markov chain on a countable state space SS with transition matrix P=(pij)i,j∈SP = (p_{ij})_{i,j \in S}, pij=Pr⁡(Xn+1=j∣Xn=i)p_{ij} = \Pr(X_{n+1} = j \mid X_n = i).

Irreducibility. The chain is irreducible if for all i,j∈Si, j \in S there exists n≥0n \ge 0 with pij(n)>0p_{ij}^{(n)} > 0, i.e., every state is reachable from every other state.

Recurrence and positive recurrence. State ii is recurrent if Pr⁡i(chain returns to i)=1\Pr_i(\text{chain returns to } i) = 1. Let Ti=inf⁡{n≥1:Xn=i}T_i = \inf\{n \ge 1 : X_n = i\} be the first return time to ii (starting from X0=iX_0 = i), and let mi=Ei[Ti]m_i = \mathbb{E}_i[T_i] be its mean. A recurrent state ii is positive recurrent if mi<∞m_i < \infty, and null recurrent if mi=∞m_i = \infty. 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 π=(π(j))j∈S\pi = (\pi(j))_{j \in S} on SS is stationary for PP if

π(j)=∑i∈Sπ(i)pijfor all j∈S,∑jπ(j)=1.\pi(j) = \sum_{i \in S} \pi(i) p_{ij} \quad \text{for all } j \in S, \qquad \sum_{j} \pi(j) = 1.

Time average. For a realization of the chain and a state jj, define the (random) long-run fraction of time spent in jj up to time nn:

Vj(n)=∑k=0n−11{Xk=j},(the number of visits to j in {0,…,n−1}),V_j(n) = \sum_{k=0}^{n-1} \mathbf{1}\{X_k = j\}, \qquad \text{(the number of visits to } j \text{ in } \{0, \dots, n-1\}\text{)},

and the time average

pˉj=lim⁡n→∞Vj(n)n,\bar{p}_j = \lim_{n \to \infty} \frac{V_j(n)}{n},

when this limit exists. The Ergodic Theorem asserts that for an irreducible positive recurrent chain, pˉj\bar p_j exists almost surely, is a.s. constant, equals 1/mj1/m_j, and equals the unique stationary probability π(j)\pi(j) — regardless of the initial distribution of X0X_0.

Intuition

Picture the chain as a train that returns again and again to a home station ii. Each time it leaves ii 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 jj) depend only on the transition matrix PP, not on the calendar time at which the excursion started. Because the future of the chain after each return to ii depends only on being at ii — 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 mi=Ei[Ti]m_i = \mathbb{E}_i[T_i], and the mean number of visits to jj per excursion, Ei[visits to j before returning to i]\mathbb{E}_i[\text{visits to } j \text{ before returning to } i]. The long-run fraction of time in jj is (visits to jj per excursion)/(length of excursion), and a renewal-reward computation shows this ratio is exactly π(j)\pi(j), with π(i)=1/mi\pi(i) = 1/m_i as the special case j=ij = i. The remarkable content of the theorem is that this ratio, built from renewal statistics, coincides precisely with the linear-algebraic object π\pi obtained by solving πP=π\pi P = \pi. The figure below shows a 33-state chain and a single simulated trajectory's histogram of time spent in each state, converging toward the bars predicted by π\pi.

Figure
A 3-state chain (left) and empirical time-fractions converging to π\pi as nn grows (right)
A B C 0.5 0.5 0.3 0.6 0.7 0.4 state A B C bars: empirical μ(n); dashed: π(j)

Central theorem

TheoremErgodic Theorem for Markov Chains

Let X=(Xn)n≥0X = (X_n)_{n \ge 0} be an irreducible, positive recurrent Markov chain on a countable state space SS with transition matrix PP, started from an arbitrary initial state or initial distribution. Then: 1. There is a unique stationary distribution π\pi on SS, given by

π(j)=1mj,mj=Ej[Tj] the mean return time to j.\pi(j) = \frac{1}{m_j}, \qquad m_j = \mathbb{E}_j[T_j] \ \text{the mean return time to } j.

2. For every state jj, almost surely,

Vj(n)n⟶π(j)as n→∞,\frac{V_j(n)}{n} \longrightarrow \pi(j) \qquad \text{as } n \to \infty,

where Vj(n)=∑k=0n−11{Xk=j}V_j(n) = \sum_{k=0}^{n-1}\mathbf{1}\{X_k=j\} is the number of visits to jj in the first nn steps, and the convergence holds regardless of the distribution of X0X_0. 3. More generally, for any bounded function f:S→Rf: S \to \mathbb{R},

1n∑k=0n−1f(Xk)⟶∑j∈Sπ(j)f(j)a.s.\frac{1}{n}\sum_{k=0}^{n-1} f(X_k) \longrightarrow \sum_{j \in S} \pi(j) f(j) \qquad \text{a.s.}
Proof

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 i∈Si \in S. By irreducibility, from any starting distribution the chain reaches ii in finite time almost surely (standard fact for irreducible countable chains: since ii communicates with every state, and the state space is countable, the chain visits ii 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 X0=iX_0 = i; the finitely many initial steps before the first visit to ii do not affect any of the a.s. limits below, since dividing by n→∞n \to \infty washes out any fixed finite prefix.

Step 1: Construct i.i.d. excursions. Define the successive return times to ii:

Ti(0)=0,Ti(r)=inf⁡{n>Ti(r−1):Xn=i},r≥1.T_i^{(0)} = 0, \qquad T_i^{(r)} = \inf\{n > T_i^{(r-1)} : X_n = i\}, \quad r \ge 1.

By recurrence of ii (which holds since the chain is positive recurrent, a fortiori recurrent), each Ti(r)T_i^{(r)} is finite almost surely, and the chain returns to ii infinitely often a.s. Define the rr-th excursion as the block of random variables

Er=(XTi(r−1),XTi(r−1)+1,…,XTi(r)),r=1,2,…E_r = \big(X_{T_i^{(r-1)}}, X_{T_i^{(r-1)}+1}, \dots, X_{T_i^{(r)}}\big), \qquad r = 1, 2, \dots

and its length Lr=Ti(r)−Ti(r−1)L_r = T_i^{(r)} - T_i^{(r-1)}. By the strong Markov property applied at the stopping times Ti(r)T_i^{(r)} (each of which is a stopping time since the event {Ti(r)=n}\{T_i^{(r)} = n\} depends only on X0,…,XnX_0, \dots, X_n), the process after time Ti(r−1)T_i^{(r-1)}, started at XTi(r−1)=iX_{T_i^{(r-1)}} = i, is a probabilistic copy of the whole chain started afresh at ii, independent of everything that happened before time Ti(r−1)T_i^{(r-1)}. Consequently the excursions E1,E2,…E_1, E_2, \dots are i.i.d. random elements (as sequences), and in particular the lengths L1,L2,…L_1, L_2, \dots are i.i.d. with

E[Lr]=Ei[Ti]=mi.\mathbb{E}[L_r] = \mathbb{E}_i[T_i] = m_i.

By positive recurrence, mi<∞m_i < \infty.

Step 2: Reward structure for visits to a state jj. For each excursion ErE_r, define the "reward"

Rr(j)=#{k:Ti(r−1)≤k<Ti(r), Xk=j},R_r(j) = \#\{k : T_i^{(r-1)} \le k < T_i^{(r)}, \ X_k = j\},

the number of visits to jj strictly within the rr-th excursion (using the half-open convention so successive excursions partition the time axis without double-counting the shared endpoint ii). Since E1,E2,…E_1, E_2, \dots are i.i.d., so are R1(j),R2(j),…R_1(j), R_2(j), \dots, with common mean

E[Rr(j)]=:γi(j)=Ei[∑k=0Ti−11{Xk=j}]<∞,\mathbb{E}[R_r(j)] =: \gamma_i(j) = \mathbb{E}_i\Big[\sum_{k=0}^{T_i - 1} \mathbf{1}\{X_k = j\}\Big] < \infty,

finite because Rr(j)≤LrR_r(j) \le L_r and E[Lr]=mi<∞\mathbb{E}[L_r] = m_i < \infty (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 L1,L2,…L_1, L_2, \ldots are i.i.d. with finite mean mim_i, the classical Kolmogorov Strong Law of Large Numbers gives

1r∑s=1rLs⟶mia.s. as r→∞.\frac{1}{r}\sum_{s=1}^r L_s \longrightarrow m_i \qquad \text{a.s. as } r \to \infty.

Note ∑s=1rLs=Ti(r)\sum_{s=1}^r L_s = T_i^{(r)}, the time of the rr-th return. So

Ti(r)r⟶mia.s.(∗)\frac{T_i^{(r)}}{r} \longrightarrow m_i \qquad \text{a.s.} \tag{$\ast$}

Similarly, since R1(j),R2(j),…R_1(j), R_2(j), \dots are i.i.d. with finite mean γi(j)\gamma_i(j), the SLLN gives

1r∑s=1rRs(j)⟶γi(j)a.s.(∗∗)\frac{1}{r}\sum_{s=1}^r R_s(j) \longrightarrow \gamma_i(j) \qquad \text{a.s.} \tag{$\ast\ast$}

Note that ∑s=1rRs(j)\sum_{s=1}^r R_s(j) counts the number of visits to jj up to time Ti(r)T_i^{(r)}, i.e. ∑s=1rRs(j)=Vj(Ti(r))\sum_{s=1}^r R_s(j) = V_j(T_i^{(r)}).

Step 4: Sandwich to convert renewal-indexed convergence to time-indexed convergence. Because the chain visits ii infinitely often a.s., for every nn there is (a.s., for nn large) a unique r=r(n)r = r(n) with Ti(r)≤n<Ti(r+1)T_i^{(r)} \le n < T_i^{(r+1)}, and r(n)→∞r(n) \to \infty as n→∞n \to \infty. Since Vj(⋅)V_j(\cdot) is nondecreasing,

Vj(Ti(r(n)))≤Vj(n)≤Vj(Ti(r(n)+1)).V_j(T_i^{(r(n))}) \le V_j(n) \le V_j(T_i^{(r(n)+1)}).

Divide through by nn and use Ti(r(n))≤n<Ti(r(n)+1)T_i^{(r(n))} \le n < T_i^{(r(n)+1)}:

Vj(Ti(r(n)))Ti(r(n)+1)≤Vj(n)n≤Vj(Ti(r(n)+1))Ti(r(n)).\frac{V_j(T_i^{(r(n))})}{T_i^{(r(n)+1)}} \le \frac{V_j(n)}{n} \le \frac{V_j(T_i^{(r(n)+1)})}{T_i^{(r(n))}}.

Write the left side as

Vj(Ti(r(n)))r(n)⋅r(n)Ti(r(n)+1)⋅Ti(r(n)+1)Ti(r(n)+1)\frac{V_j(T_i^{(r(n))})}{r(n)} \cdot \frac{r(n)}{T_i^{(r(n)+1)}} \cdot \frac{T_i^{(r(n)+1)}}{T_i^{(r(n)+1)}}

more directly: using (∗)(\ast) and (∗∗)(\ast\ast) along the (a.s. infinite) subsequence r(n)→∞r(n) \to \infty,

Vj(Ti(r(n)))r(n)→γi(j),Ti(r(n))r(n)→mi,Ti(r(n)+1)r(n)+1→mi,r(n)+1r(n)→1,\frac{V_j(T_i^{(r(n))})}{r(n)} \to \gamma_i(j), \qquad \frac{T_i^{(r(n))}}{r(n)} \to m_i, \qquad \frac{T_i^{(r(n)+1)}}{r(n)+1}\to m_i, \qquad \frac{r(n)+1}{r(n)}\to 1,

all almost surely (as r(n)→∞r(n)\to\infty a.s.). Multiplying/dividing these a.s. limits (all nondegenerate, positive, finite constants) shows both the lower and upper bounds on Vj(n)/nV_j(n)/n converge to the same limit

γi(j)mi.\frac{\gamma_i(j)}{m_i}.

By the squeeze theorem, almost surely,

Vj(n)n⟶γi(j)mi.(1)\frac{V_j(n)}{n} \longrightarrow \frac{\gamma_i(j)}{m_i}. \tag{1}

Step 5: Identify the limit with π(j)\pi(j). Set π(j):=γi(j)/mi\pi(j) := \gamma_i(j)/m_i for each jj. First check π\pi is a probability distribution: summing γi(j)\gamma_i(j) over j∈Sj \in S counts every one of the TiT_i steps of a single excursion exactly once (since every visited state XkX_k, 0≤k<Ti0 \le k < T_i, is some state jj), so

∑j∈Sγi(j)=Ei[Ti]=mi  ⟹  ∑jπ(j)=1.\sum_{j \in S} \gamma_i(j) = \mathbb{E}_i[T_i] = m_i \implies \sum_j \pi(j) = 1.

Also π(j)≥0\pi(j) \ge 0 for all jj. Taking j=ij = i: every excursion visits ii exactly once in [Ti(r−1),Ti(r))[T_i^{(r-1)}, T_i^{(r)}) (at its start), so γi(i)=1\gamma_i(i) = 1 and π(i)=1/mi\pi(i) = 1/m_i, matching the claimed formula π(j)=1/mj\pi(j) = 1/m_j at j=ij = i; since ii was an arbitrary state, this gives π(j)=1/mj\pi(j) = 1/m_j for every jj (applying the whole argument with reference state jj in place of ii and reading off π(j)=1/mj\pi(j) = 1/m_j directly, or by the stationarity argument below combined with uniqueness). Next, show π\pi is stationary, i.e., πP=π\pi P = \pi. This is the standard renewal/occupation-measure computation: consider ∑lγi(l)plj\sum_l \gamma_i(l) p_{lj}. By definition,

γi(l)=Ei[∑k=0Ti−11{Xk=l}],\gamma_i(l) = \mathbb{E}_i\Big[\sum_{k=0}^{T_i-1}\mathbf 1\{X_k = l\}\Big],

so, using the Markov property to write Pr⁡i(Xk=l,Xk+1=j,k<Ti)=Pr⁡i(Xk=l,k<Ti) plj\Pr_i(X_k = l, X_{k+1}=j, k < T_i) = \Pr_i(X_k=l,k<T_i)\,p_{lj} (valid because {k<Ti}\{k < T_i\} is determined by X0,…,XkX_0,\dots,X_k, so conditioning on Xk=lX_k = l and k<Tik < T_i, the next step's transition still uses row ll of PP),

∑lγi(l) plj=∑l∑k≥0Pr⁡i(Xk=l, k<Ti) plj=∑k≥0Pr⁡i(Xk+1=j, k<Ti)=∑k≥1Pr⁡i(Xk=j, k≤Ti).\sum_l \gamma_i(l)\,p_{lj} = \sum_l \sum_{k \ge 0}\Pr_i(X_k = l,\, k< T_i)\,p_{lj} = \sum_{k\ge 0}\Pr_i(X_{k+1}=j,\, k< T_i) = \sum_{k \ge 1} \Pr_i(X_k = j,\, k \le T_i).

For j≠ij \ne i: the events {Xk=j, k≤Ti}\{X_k=j,\,k\le T_i\} for k≥1k\ge1 equal {Xk=j, k<Ti}\{X_k=j,\,k<T_i\} (since XTi=i≠jX_{T_i}=i\neq j), so the sum equals γi(j)\gamma_i(j) exactly by definition (re-indexing k≥1k \ge 1 vs. k≥0k\ge0 costs nothing since the k=0k=0 term Pr⁡i(X0=j)=0\Pr_i(X_0=j)=0 as X0=i≠jX_0=i\ne j). For j=ij = i: the sum is ∑k≥1Pr⁡i(Xk=i, k≤Ti)=Pr⁡i(XTi=i)=1=γi(i)\sum_{k\ge1}\Pr_i(X_k=i,\,k\le T_i) = \Pr_i(X_{T_i}=i) = 1= \gamma_i(i) (the only k≤Tik\le T_i with Xk=iX_k=i and k≥1k\ge1 is k=Tik=T_i, by definition of TiT_i as the first return). In both cases,

∑lγi(l) plj=γi(j).\sum_l \gamma_i(l)\, p_{lj} = \gamma_i(j).

Dividing by mim_i gives ∑lπ(l)plj=π(j)\sum_l \pi(l) p_{lj} = \pi(j) for all jj, i.e. πP=π\pi P = \pi: π\pi is stationary.

Step 6: Uniqueness of the stationary distribution. Suppose ν\nu is any stationary distribution. By induction, νPn=ν\nu P^n = \nu for all n≥0n \ge 0. Consider ∑iν(i) Ei[Vj(n)]/n\sum_i \nu(i)\,\mathbb{E}_i[V_j(n)]/n — since Ei[Vj(n)]=∑k=0n−1pij(k)\mathbb{E}_i[V_j(n)] = \sum_{k=0}^{n-1}p_{ij}^{(k)} and ν\nu is stationary, ∑iν(i)pij(k)=ν(j)\sum_i \nu(i) p_{ij}^{(k)} = \nu(j) for every kk, so

Eν[Vj(n)n]=1n∑k=0n−1∑iν(i)pij(k)=ν(j)for all n.\mathbb{E}_\nu\Big[\frac{V_j(n)}{n}\Big] = \frac{1}{n}\sum_{k=0}^{n-1}\sum_i \nu(i)p_{ij}^{(k)} = \nu(j) \quad \text{for all } n.

But Vj(n)/nV_j(n)/n is a bounded (≤1\le 1) sequence converging a.s. (by Step 4, valid started from any state, hence from ν\nu by conditioning) to the constant π(j)\pi(j); by the Bounded Convergence Theorem, Eν[Vj(n)/n]→π(j)\mathbb{E}_\nu[V_j(n)/n] \to \pi(j). Comparing the two, ν(j)=π(j)\nu(j) = \pi(j) for every jj. Hence the stationary distribution is unique and equals the π\pi 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 ii eventually (guaranteed by irreducibility from any start) and is thereafter a copy of the chain started at ii.

Step 7: Extend to bounded functions ff (part 3). Let f:S→Rf: S \to \mathbb{R} be bounded, ∣f∣≤M<∞|f| \le M < \infty. For finite SS, or more generally when ∑j∣f(j)∣π(j)<∞\sum_j |f(j)|\pi(j) < \infty (automatic if ff is bounded, since ∑jπ(j)=1\sum_j \pi(j) = 1),

1n∑k=0n−1f(Xk)=∑j∈Sf(j)Vj(n)n.\frac{1}{n}\sum_{k=0}^{n-1} f(X_k) = \sum_{j \in S} f(j) \frac{V_j(n)}{n}.

If SS is finite this is a finite sum of terms each converging a.s. by part (2), so the whole sum converges a.s. to ∑jf(j)π(j)\sum_j f(j)\pi(j). If SS is countably infinite, fix ε>0\varepsilon>0 and choose a finite set F⊂SF \subset S with ∑j∉Fπ(j)<ε\sum_{j \notin F}\pi(j) < \varepsilon (possible since π\pi is a probability measure); one shows, using (∗∗)(\ast\ast)-type renewal bounds uniformly summable over j∉Fj \notin F (justified because ∑j∉Fγi(j)=mi−∑j∈Fγi(j)→0\sum_{j\notin F}\gamma_i(j) = m_i - \sum_{j \in F}\gamma_i(j) \to 0 as F↑SF \uparrow S, an immediate consequence of ∑jγi(j)=mi<∞\sum_j \gamma_i(j)=m_i<\infty and dominated convergence for the series), that the tail contribution ∑j∉Ff(j)Vj(n)/n\sum_{j\notin F} f(j) V_j(n)/n is a.s. eventually bounded by 2Mε2M\varepsilon, while the finite part converges exactly as in the finite case; letting ε→0\varepsilon \to 0 gives the general result. ■\blacksquare

∎

Worked examples

Example 1 (three-state chain, asymmetric transition probabilities). Let S={A,B,C}S = \{A, B, C\} with transition matrix (rows A,B,CA,B,C)

P=(00.50.50.400.60.70.30).P = \begin{pmatrix} 0 & 0.5 & 0.5 \\ 0.4 & 0 & 0.6 \\ 0.7 & 0.3 & 0 \end{pmatrix}.

This matches the diagram above (with the arrow labels A→BA\to B: 0.50.5, A→CA \to C: 0.50.5, B→AB \to A: 0.40.4, B→CB\to C: 0.60.6, C→AC \to A: 0.70.7, C→BC \to B: 0.30.3). It is irreducible (every state reachable from every other in ≤2\le 2 steps: A→B→AA\to B\to A, A→C→BA \to C \to B, 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 πP=π\pi P = \pi, π(A)+π(B)+π(C)=1\pi(A)+\pi(B)+\pi(C)=1:

π(A)=0.4π(B)+0.7π(C),π(B)=0.5π(A)+0.3π(C),π(C)=0.5π(A)+0.6π(B).\pi(A) = 0.4\pi(B) + 0.7\pi(C), \qquad \pi(B) = 0.5\pi(A) + 0.3\pi(C), \qquad \pi(C) = 0.5\pi(A) + 0.6\pi(B).

From the second equation, π(B)=0.5π(A)+0.3π(C)\pi(B) = 0.5\pi(A) + 0.3\pi(C). Substitute into the first:

π(A)=0.4(0.5π(A)+0.3π(C))+0.7π(C)=0.2π(A)+0.12π(C)+0.7π(C)=0.2π(A)+0.82π(C),\pi(A) = 0.4(0.5\pi(A)+0.3\pi(C)) + 0.7\pi(C) = 0.2\pi(A) + 0.12\pi(C) + 0.7\pi(C) = 0.2\pi(A) + 0.82\pi(C),

so 0.8π(A)=0.82π(C)0.8\pi(A) = 0.82\pi(C), giving π(A)=1.025 π(C)\pi(A) = 1.025\,\pi(C). Substitute π(A)=1.025π(C)\pi(A) = 1.025\pi(C) into π(B)=0.5π(A)+0.3π(C)=0.5125π(C)+0.3π(C)=0.8125π(C)\pi(B) = 0.5\pi(A)+0.3\pi(C) = 0.5125\pi(C) + 0.3\pi(C) = 0.8125\pi(C). Normalize: π(A)+π(B)+π(C)=(1.025+0.8125+1)π(C)=2.8375 π(C)=1\pi(A)+\pi(B)+\pi(C) = (1.025 + 0.8125 + 1)\pi(C) = 2.8375\,\pi(C) = 1, so

π(C)=12.8375≈0.35242,π(A)=1.025×0.35242≈0.36123,π(B)=0.8125×0.35242≈0.28634.\pi(C) = \frac{1}{2.8375} \approx 0.35242, \qquad \pi(A) = 1.025 \times 0.35242 \approx 0.36123, \qquad \pi(B) = 0.8125 \times 0.35242 \approx 0.28634.

Check normalization: 0.36123+0.28634+0.35242=0.99999≈10.36123 + 0.28634 + 0.35242 = 0.99999 \approx 1 ✓. Check stationarity of π(C)\pi(C) directly: 0.5(0.36123)+0.6(0.28634)=0.18062+0.17180=0.352420.5(0.36123) + 0.6(0.28634) = 0.18062 + 0.17180 = 0.35242 ✓. By the Ergodic Theorem, no matter whether the frog starts at AA, BB, or CC, its long-run fraction of hops landing on CC converges almost surely to 0.35242…0.35242\ldots, and the mean return time to CC is mC=1/π(C)≈2.8375m_C = 1/\pi(C) \approx 2.8375 steps.

Example 2 (a birth–death chain on {0,1,2,3}\{0,1,2,3\} with reflecting boundaries, asymmetric rates). Let S={0,1,2,3}S=\{0,1,2,3\} with p01=1p_{01}=1 (reflecting at 00), pi,i+1=0.6p_{i,i+1}=0.6, pi,i−1=0.4p_{i,i-1}=0.4 for i=1,2i=1,2, and p32=1p_{32}=1 (reflecting at 33). This chain is irreducible (a path connects any two states) and finite, hence ergodic (positive recurrent). Detailed balance holds for birth–death chains: π(i)pi,i+1=π(i+1)pi+1,i\pi(i) p_{i,i+1} = \pi(i+1)p_{i+1,i} (this is a standard shortcut, but let us not assume it and instead verify πP=π\pi P=\pi directly to keep the example self-contained and honest about hypotheses). Guess via detailed balance: π(0)p01=π(1)p10⇒π(0)(1)=π(1)(0.4)⇒π(1)=2.5 π(0)\pi(0) p_{01} = \pi(1)p_{10} \Rightarrow \pi(0)(1) = \pi(1)(0.4) \Rightarrow \pi(1) = 2.5\,\pi(0). Next π(1)p12=π(2)p21⇒π(1)(0.6)=π(2)(0.4)⇒π(2)=1.5 π(1)=3.75 π(0)\pi(1)p_{12} = \pi(2)p_{21} \Rightarrow \pi(1)(0.6) = \pi(2)(0.4) \Rightarrow \pi(2) = 1.5\,\pi(1) = 3.75\,\pi(0). Next π(2)p23=π(3)p32⇒π(2)(0.6)=π(3)(1)⇒π(3)=0.6 π(2)=2.25 π(0)\pi(2)p_{23} = \pi(3)p_{32} \Rightarrow \pi(2)(0.6) = \pi(3)(1) \Rightarrow \pi(3) = 0.6\,\pi(2) = 2.25\,\pi(0). Normalize: π(0)(1+2.5+3.75+2.25)=π(0)(9.5)=1\pi(0)(1 + 2.5 + 3.75 + 2.25) = \pi(0)(9.5) = 1, so π(0)=1/9.5≈0.10526\pi(0) = 1/9.5 \approx 0.10526, and

π(1)≈0.26316,π(2)≈0.39474,π(3)≈0.23684.\pi(1) \approx 0.26316, \qquad \pi(2) \approx 0.39474, \qquad \pi(3) \approx 0.23684.

Verify detailed balance implies global balance (a fact that must be checked, not assumed, though it is standard for birth-death chains): for state 11, in-flow =π(0)p01+π(2)p21=0.10526(1)+0.39474(0.4)=0.10526+0.15790=0.26316=π(1)= \pi(0)p_{01} + \pi(2)p_{21} = 0.10526(1) + 0.39474(0.4) = 0.10526+0.15790=0.26316=\pi(1) ✓ matching out-flow trivially since π(1)\pi(1) is exactly this quantity by construction. A direct check of the full balance equation at state 22: π(2)=π(1)p12+π(3)p32=0.26316(0.6)+0.23684(1)=0.15790+0.23684=0.39474\pi(2) = \pi(1)p_{12}+\pi(3)p_{32} = 0.26316(0.6) + 0.23684(1) = 0.15790+0.23684 = 0.39474 ✓, confirming stationarity. The Ergodic Theorem now guarantees: starting from any state, e.g. X0=3X_0 = 3, the long-run proportion of time the chain spends at state 22 converges almost surely to π(2)≈0.39474\pi(2) \approx 0.39474, and the mean recurrence time to state 00 is m0=1/π(0)=9.5m_0 = 1/\pi(0) = 9.5 steps.

CounterexampleDropping positive recurrence: a null recurrent chain has no long-run occupation frequency

Consider simple symmetric random walk on S=ZS = \mathbb{Z}: pi,i+1=pi,i−1=1/2p_{i,i+1} = p_{i,i-1} = 1/2 for every i∈Zi \in \mathbb{Z}. 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 00 with probability 11 — but null recurrent: m0=E0[T0]=∞m_0 = \mathbb{E}_0[T_0] = \infty. 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 T0(r)/r→m0=∞T_0^{(r)}/r \to m_0 = \infty 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, Vj(n)/n→0V_j(n)/n \to 0 for every state jj. Indeed one can show directly Vj(n)/n→0V_j(n)/n \to 0 a.s. for every fixed jj on Z\mathbb{Z}: the chain spends a vanishing fraction of time at any single site as n→∞n\to\infty, consistent with there being no stationary probability distribution at all (the only nonnegative solution to πP=π\pi P=\pi with π=(…,1,1,1,…)\pi=(\ldots,1,1,1,\ldots), up to constant scaling, is not summable to 11 over Z\mathbb{Z}). This shows precisely what positive recurrence buys us: without it, the "space average" π\pi 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 mi<∞m_i < \infty, not merely recurrence.

Scope, edge cases & common traps

SituationWhat holdsWhat fails / must not be assumed
Irreducible, positive recurrent (finite or countable SS)Unique π\pi; Vj(n)/n→π(j)V_j(n)/n \to \pi(j) a.s., any start—
Irreducible, positive recurrent, periodicTime averages still converge to π(j)\pi(j)Pn(i,j)→π(j)P^n(i,j) \to \pi(j) fails (e.g. period 2 chain: pij(n)p_{ij}^{(n)} oscillates)
Irreducible, null recurrentNo stationary probability distribution existsTime average of every state is 00, not π(j)\pi(j)
Irreducible, transientChain a.s. leaves every finite set eventuallyNo stationary distribution; occupation counts Vj(n)V_j(n) stay a.s. finite (bounded), not Θ(n)\Theta(n)
Reducible chainErgodic theorem applies within each closed communicating class separatelyGlobal time average depends on which class is absorbed into; no single π\pi governs the whole space
Finite state space, irreduciblePositive recurrence is automaticCommon 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
AA
Andrei Andreyevich Markov
1856–1922 · Imperial Academy of Sciences, St. Petersburg, Russia

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.

History
- 1906 — Markov defines dependent chains and proves a law-of-large-numbers-type result for them, the conceptual seed of the Ergodic Theorem.
- 1907–1908 — Markov extends the theory to chains with countably many states and studies convergence properties.
- 1930s — Andrei Kolmogorov and others place Markov chain theory on rigorous measure-theoretic foundations, formalizing recurrence and stationary distributions.
- 1936–1938 — the classification into transient, null recurrent, and positive recurrent states (crucial to the modern statement) is fully worked out, notably in work connected to Kolmogorov and William Feller.
- 1950s onward — the renewal-theoretic proof technique used here (excursion decomposition) becomes standard, tracing to the general renewal theory developed by Feller and Paul Erdős–Kac-adjacent probabilists, and is codified in textbooks by Chung, Feller, and later Ross and Grimmett–Stirzaker.
Does the Ergodic Theorem require the chain to be aperiodic?

No. The theorem as stated — that time averages Vj(n)/nV_j(n)/n converge almost surely to π(j)\pi(j) — requires only irreducibility and positive recurrence. Aperiodicity is a separate, additional hypothesis needed only for the different (stronger, pointwise) claim that Pn(i,j)→π(j)P^n(i,j) \to \pi(j) as n→∞n \to \infty 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 nn-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 PP) 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 π(j)=1/mj\pi(j) = 1/m_j, an identity that spectral methods obscure.

Is the limit π(j)\pi(j) 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 Vj(n)V_j(n) itself is a random variable for each fixed nn, the limiting ratio Vj(n)/nV_j(n)/n converges, with probability 11, to the deterministic constant π(j)\pi(j) that depends only on the transition matrix PP (via mj=Ej[Tj]m_j = \mathbb E_j[T_j]), 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 1/21/2, not to some random limit.

Does the starting distribution of X0X_0 affect the long-run time average?

No — this is one of the theorem's most powerful features. Regardless of whether X0X_0 is deterministic (a fixed state) or has an arbitrary initial distribution, and regardless of what that distribution is, the almost-sure limit of Vj(n)/nV_j(n)/n is always π(j)\pi(j). The proof shows this because, by irreducibility, the chain a.s. reaches the reference state ii in finite time from any start, and the excursion structure used afterward depends only on being at ii, discarding all memory of X0X_0. Only the finite prefix before the first hit of ii differs across starting distributions, and finite prefixes vanish upon dividing by n→∞n \to \infty.

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 11, but the mean return time is infinite. In this case no stationary probability distribution exists (any nonnegative solution to πP=π\pi P = \pi 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 Vj(n)/nV_j(n)/n converges almost surely to 00 for every state jj, rather than to a positive stationary probability. The simple symmetric random walk on Z\mathbb{Z} 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 TT on a probability space, time averages 1n∑k<nf(Tkx)\frac1n\sum_{k<n} f(T^k x) converge a.s. to the space average ∫f dμ\int f \, d\mu. The Markov chain version here is a special case: run the chain on the (typically infinite) path space with the shift map as TT and the law of the stationary chain as μ\mu; irreducibility and positive recurrence together imply TT 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 jj converges almost surely to π(j)\pi(j), where π\pi solves the stationary equations for the generator matrix QQ (i.e. πQ=0\pi Q = 0), 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.

Before this

Where this leads