TL;DR
A Markov chain is a sequence of random states, one per time step, where the probability of the next state depends only on the state you are in now. The rest of the history is forgotten. Each state has a fixed set of probabilities for where it goes next, collected in a transition matrix.
Run the chain for long enough and, for many chains, the probability of being in each state settles to a fixed pattern called the stationary distribution, no matter where you started.
Where you'll see it: in the forward noising steps of a diffusion model, in the PageRank algorithm that ranks web pages, and in Markov chain Monte Carlo, which samples from distributions too complicated to sample directly.
Intuition
Forgetting the past on purpose
Think of a weather model that only says "sunny" or "rainy". Tomorrow's weather is random, but the odds are not the same every day. If today is sunny, tomorrow is probably sunny too. If today is rainy, the odds tilt the other way.
The Markov idea is that these odds depend only on today. It does not matter that it rained all last week, or that the forecast is unusual this month. Once you know today's state, the past adds nothing to the forecast for tomorrow. This is called the Markov property, and it is a strong simplification. It is also what makes the model tractable: you only need one table of numbers, not a record of every day.
Why do we want this? Many processes look like this at the level we care about. A customer moves between "free", "paying" and "cancelled". A web surfer jumps between pages. A letter in a sentence depends mostly on the letter before it. Writing down the full history would be hopeless, but writing down one step at a time is easy.
- P(sunny on day n | sunny today)
- long-run value 5/6
The math
Definition
A sequence of random variables taking values in a finite or countable set of states is a Markov chain if, for every time and every choice of states ,
When the right-hand side does not depend on , the chain is time-homogeneous, and we write it as .
The vertical bar means "given that". The left side conditions on the entire history. The right side conditions only on the present state. That equality is the Markov property. The numbers are the transition probabilities: the chance of moving from state to state in one step. They are conditional probabilities, so for each fixed they must add to 1 over all .
Collect them into a matrix , with entry in row and column . Each row is a probability distribution, so every row sums to 1. Such a matrix is called a row-stochastic matrix.
Distributions as row vectors
Let be the row vector whose -th entry is . Then splitting on the current state with the law of total probability gives
Each step is one matrix multiplication. Starting from , after steps we have . The entries of are the -step transition probabilities.
Stationary distribution
A row vector is a stationary distribution if it is a probability vector (entries non-negative, summing to 1) and
If the chain starts in , it stays in forever. For a finite chain that is irreducible (any state can reach any other) and aperiodic (no rigid cycle in the timing of returns), there is exactly one stationary distribution, and converges to it for every starting distribution . This convergence is what makes Markov chains useful for sampling and for ranking.
To find , solve the linear system together with .
Two-state chains
A two-state chain with and has stationary distribution
The stationary probability of a state is larger when it is harder to leave. The formula comes from balancing the flow into and out of each state, which is the same as solving the system above for two states.
Worked examples
States are sunny (S) and rainy (R). The transition matrix is
so a sunny day stays sunny with probability 0.9, and a rainy day turns sunny with probability 0.5.
- Start certain it is sunny: .
- One step: . Matches the first row of .
- Two steps: .
- Stationary distribution: set , which gives , so . With , we get and .
- Check: . It is unchanged.
Interpretation: the chance of sunny starts at 1, then slides to 0.9 and 0.86, and keeps closing in on . In the long run about five days in six are sunny, whatever today was. The plot above shows the same convergence in closed form.
A customer is in one of three states each month: Free, Paid, or Cancelled. The transitions are:
| From | To Free | To Paid | To Cancelled |
|---|---|---|---|
| Free | 0.6 | 0.3 | 0.1 |
| Paid | 0 | 0.8 | 0.2 |
| Cancelled | 0 | 0 | 1 |
A new customer starts Free, so .
- After month one: .
- After month two, take each entry of times the matching column of :
- Free: (only Free feeds Free).
- Paid: .
- Cancelled: .
- Check: .
Interpretation: after two months, 22% of customers have already cancelled. Cancelled is absorbing, since once there the chain never leaves. So in the long run every customer ends there, and the stationary distribution is concentrated on Cancelled. This is why the question for a business is usually not the stationary distribution but the expected time until absorption.
Tradeoffs and failure modes
The Markov assumption is powerful and often wrong. Use it when the current state really does carry the information you need.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Behaviour depends on a longer history | A one-step chain throws away the useful context | Enlarge the state to include the history, or use a higher-order chain |
| Transition probabilities change over time | A fixed matrix cannot describe the process | Use a time-inhomogeneous chain or a hidden Markov model |
| The chain has more than one long-run pattern | The stationary distribution is not unique, so the answer depends on the start | Check irreducibility, or condition on the starting state |
| The state space is huge | Writing down is impossible | Simulate the chain instead of computing with the matrix (Monte Carlo) |
| Hidden states drive what you observe | You cannot see the chain's state directly | Use a [[latent-variable-model |
A common error is treating a chain as Markov because its current state is easy to write down, when the true dynamics depend on something not in the state. Check whether conditioning on the present really makes the past irrelevant.
History
Andrey Markov, a Russian mathematician, introduced the idea in 1906 while studying sequences of linked random events, partly to argue that independence is not necessary for the law of large numbers. The problem he was solving was how far probability theory could go beyond independent trials. He applied the idea about 1913 to letters in Pushkin's novel Eugene Onegin, counting how often vowels followed consonants.
It caught on because it was simple enough to compute and general enough to model queues, genetics and language. Its biggest modern impact came from simulation. Markov chains underlie the Metropolis algorithm of 1953, and in the 1990s, researchers found they could sample from complicated distributions by running a carefully designed chain, which made Bayesian inference practical for many problems.
Check yourself
QuestionFor a chain with transition matrix , what is the probability of being in state 1 after two steps, starting from state 1?Show answer
Start with . After one step, . After two steps, the first entry is . The answer is .
QuestionUsing the same matrix as before, find the stationary distribution.Show answer
Solve , which gives , so . With we get and . Check: the two-state formula gives . The answer is .
QuestionWhy does the Markov property make a model easier to store and compute with, and what does it cost in realism?Show answer
Under the Markov property, the full history never needs to be stored. The whole model is one transition matrix whose size depends on the number of states, not on how long the process has run. The cost is that the model assumes the present state holds all relevant information. If the true process depends on a longer history, the chain will miss patterns that a richer state would capture.
QuestionA chain reaches a state from which it can never leave. What does that do to the stationary distribution, and why?Show answer
That state is absorbing. Once the chain is there, it stays forever, so over time all probability flows into it. The stationary distribution puts all its mass on the absorbing state, and the other states get zero. Uniqueness can also fail, because each absorbing state gives its own stationary distribution, which is why the irreducibility condition matters.
QuestionIn a diffusion model, the forward process adds a little Gaussian noise at each step, and each step depends only on the previous image. Why is that a Markov chain, and why does the design choice matter?Show answer
Each noisy image depends only on the image one step before it, not on the earlier history, so the sequence has the Markov property. This matters because the reverse process can then be learned one step at a time, and the forward chain has a closed form for jumping to any step, which keeps training fast. The Markov structure is what turns a long noising procedure into a sequence of simple, learnable steps.