TL;DR
A Markov chain has a stationary distribution when the total probability flowing into each state equals the total flowing out. Detailed balance is a stronger, pairwise condition: for every pair of states, the flow from to equals the flow from to . Any chain that satisfies it has as a stationary distribution, and that check is usually much easier than checking the global balance equations.
Where you'll see it: in the proof that the Metropolis algorithm samples the right distribution, and in the design of Markov chain Monte Carlo samplers in general.
Intuition
Two tanks and a pipe
Picture two tanks joined by a pipe. Water flows from one to the other, and the amount of water in each tank can stay constant over time. The water level is stable overall if inflow equals outflow for each tank. It is stable in a stronger sense if, between any two tanks, the water moving one way per second equals the water moving the other way. Then no net current flows along any pipe at all.
A Markov chain works the same way. A state is a tank, and the probability of jumping from one state to another per step is the flow along a pipe. Stationarity says the total flow in and out of each state balances. Detailed balance says the flow along each individual pipe balances, so there is no net circulation between any pair of states.
The plot below shows the function that the Metropolis algorithm uses to make this happen, which we come back to later.
- acceptance probability min(1, r)
The math
Definition
Let be the probability of moving from state to state in one step, and let be a probability vector over states.
A chain with transition probabilities satisfies detailed balance with respect to if, for every pair of states and ,
A chain with this property is called reversible.
Read the equation in words. The left side is the stationary probability of being in , times the chance of moving from to : the flow along the pipe from to . The right side is the same flow in the other direction. The condition says the two flows match, for every pair. The pair is trivially true.
In a continuous state space, sums become integrals and the matrix becomes a transition density . The condition reads
for all and . Everything below carries over with that substitution.
Detailed balance implies stationarity
Suppose detailed balance holds. Look at the -th entry of :
Replace each term using detailed balance, :
The last step uses the fact that each row of sums to 1: the probabilities of leaving state add up to 1. So , and is stationary.
This is the reason detailed balance is so useful. You do not need to solve the linear system . You check one equation for each pair of states, and each one involves only two states.
Detailed balance is sufficient, not necessary
The converse fails. A chain can have a stationary distribution without detailed balance, because probability can circulate around a loop. Consider three states arranged in a cycle, where the chain always moves . Every state has the same flow in and out, so the uniform distribution is stationary. But the flow from 1 to 2 is positive while the flow from 2 to 1 is zero, so detailed balance fails. Such a chain is called non-reversible. Its stationary distribution is still correct, but you cannot prove that with the pairwise test.
Why it matters for sampling
Markov chain Monte Carlo builds a chain whose stationary distribution is a target that is hard to sample directly. The recipe is to design transition probabilities, check detailed balance with respect to , and conclude that is stationary. Then run the chain and average along it.
The check is far simpler than the global equations, because the target often appears only through ratios. Detailed balance can be rewritten as
The normalising constant of cancels in the ratio. This is why MCMC works when you know only up to a constant.
The Metropolis construction
Choose a symmetric proposal, meaning , which says how likely you are to suggest moving from to . Then from state , propose and accept it with probability
Otherwise stay at . The transition probability for is .
Check detailed balance for :
The right side is symmetric in and , because is symmetric. Swapping the roles gives the same expression, so detailed balance holds. The construction works because is the same whichever direction you look from.
Worked examples
Let sunny and rainy be the states. Suppose and .
- Detailed balance with the unknown (sunny) and (rainy) says .
- So .
- With , we get , so and .
- Check against the two-state formula . It matches.
- Interpretation: in the long run the chain is sunny two days in three. The pairwise balance gave the answer in one line, with no matrix to invert.
Three states have unnormalised target weights , and , so . The proposal picks one of the other two states with probability each, which is symmetric.
- Acceptance probabilities: from 1 to 2, . From 2 to 1, . From 2 to 3, . From 3 to 2, . From 1 to 3, . From 3 to 1, .
- Transition probabilities for are acceptance: , , , , , .
- Stay probabilities fill each row to 1: , , and .
- Check detailed balance on the pair (1, 2): , and . They match.
- Check the pair (2, 3): , and . They match.
- Interpretation: the chain visits state 3, the heaviest state, most often, in proportion to its weight. It never needed the normalising constant 7, because every acceptance step used only the ratios of weights.
A chain on three states moves deterministically , so .
- The uniform distribution is stationary, because each state receives exactly one unit of probability from its predecessor and sends one unit onward.
- Detailed balance on the pair (1, 2) asks . The left side is , and the right side is , because .
- So detailed balance fails, even though stationarity holds.
- Interpretation: this chain circulates probability around the loop. Stationarity is a global statement, and detailed balance is a stronger local one that forbids circulation.
Tradeoffs and failure modes
Detailed balance is a design tool, and it has limits.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Chain has useful circulation (directed sweeps through the state space) | Reversible chains can mix slowly when they must retrace their steps | Non-reversible samplers, which keep the stationary distribution but move with momentum |
| Proposal is not symmetric | The simple acceptance rule no longer satisfies detailed balance | Metropolis–Hastings, which adds a correction factor to the ratio |
| Acceptance is very low | Almost every proposal is rejected, so the chain stays put | Smaller steps for random walks, or gradient-based proposals |
| The normalising constant of the target is unknown | Computing exactly would be impractical | Nothing needed: the ratios in the acceptance rule cancel the constant |
| You need the answer by a deadline | Detailed balance guarantees the stationary distribution, not the speed of convergence | Diagnose mixing with running averages or multiple chains |
A frequent error is to check detailed balance and forget that it proves only stationarity. The chain also has to be irreducible and aperiodic for the long-run average to converge to the expectation under .
History
Detailed balance came from statistical physics in the nineteenth century. Ludwig Boltzmann studied how gases approach equilibrium, and the idea that each microscopic process is balanced by its reverse grew out of that work. In the early twentieth century, physicists described it as "microscopic reversibility" or the principle of detailed balance, and it became a standard tool for showing that a system settles into the Boltzmann distribution.
The Metropolis algorithm was introduced in 1953 by Nicholas Metropolis, Arianna Rosenbluth, Marshall Rosenbluth, Augusta Teller and Edward Teller. They used it to simulate a gas of interacting molecules, which was too large to enumerate, and the acceptance rule was built so that the simulated system obeyed detailed balance with the Boltzmann distribution. W. Keith Hastings generalised it in 1970 to asymmetric proposals, which gave the Metropolis–Hastings algorithm used in statistics today. The pairwise check is the standard way to prove that these samplers are correct.
Check yourself
QuestionWrite the detailed balance condition for a chain with transition probabilities and stationary distribution . Why does it imply that is stationary?Show answer
Detailed balance says for all pairs . Summing over gives , because each row of sums to 1. That is exactly the stationarity equation .
QuestionA two-state chain has and . Find the stationary distribution using detailed balance.Show answer
Detailed balance gives , so . With , we get and . This agrees with the formula .
QuestionWhy does the Metropolis acceptance rule work even when the target distribution is known only up to a normalising constant?Show answer
The acceptance probability depends only on the ratio . The detailed balance check is , and the normalising constant appears in both and in a way that cancels in every ratio. The chain therefore needs only the unnormalised weights.
QuestionA sampler's chain balances the flow into and out of every state, but you suspect it circulates probability around loops. A colleague says the stationary distribution is still correct. Are they right, and what test would you use to check the circulation?Show answer
They are right that stationarity is a global condition, so a circulating chain can still have the correct stationary distribution. Circulation is not detected by the global check. You would test detailed balance pair by pair. If some pair has , the chain is non-reversible. That is not an error, but it changes how quickly the chain explores the space, and it means the pairwise test cannot be used to prove correctness.