A Markov chain is a stochastic process over a set of states in which the probability of moving to the next state depends only on the current state, not on the sequence of states that preceded it. This memoryless property, called the Markov property, makes the Markov chain one of the foundational probabilistic models in artificial intelligence, underlying sampling algorithms, sequence models and reinforcement learning.
The term Markov process is often used as a synonym, although many authors reserve it for processes in continuous time or continuous state spaces. In machine learning, the discrete-time chain with a finite or countable state space is the most common form, and it serves as the basis for hidden Markov models, Markov chain Monte Carlo and Markov decision processes.
How a Markov chain evolves from state to state
A discrete-time Markov chain is fully specified by a state space, an initial distribution and a transition matrix. The transition matrix P holds the probability P[i][j] of moving from state i to state j in one step, and every row sums to exactly 1.
Formally, the Markov property states that P(X_{t+1} = j | X_t = i, X_{t-1}, ..., X_0) = P(X_{t+1} = j | X_t = i). Because of this property, the distribution after n steps is obtained by multiplying the initial distribution by P raised to the power n, which turns questions about long sequences into linear algebra.
The table below lists the components that define a chain and the role each one plays.
| Component | Notation | Role |
|---|---|---|
| State space | S | Set of all possible states |
| Initial distribution | π0 | Probabilities of the starting state |
| Transition matrix | P | One-step probabilities between states |
| n-step transition | P to the power n | Probabilities after n steps |
| Stationary distribution | π with πP = π | Long-run share of time in each state |
A chain is time-homogeneous when P does not change over time. Time-inhomogeneous chains, in which transition probabilities depend on t, appear in simulated annealing and in some sequence models, but most theory assumes homogeneity.
Key properties: irreducibility, periodicity and stationarity
The long-run behavior of a Markov chain is governed by a small set of structural properties. Together they determine whether the chain settles into a unique stationary distribution regardless of where it starts.
| Property | Meaning | Why it matters |
|---|---|---|
| Irreducible | Every state can reach every other state | Rules out isolated groups of states |
| Aperiodic | Returns are not locked to a fixed cycle | Prevents oscillation between state groups |
| Positive recurrent | Expected return time is finite | Guarantees a stationary distribution exists |
| Ergodic | Irreducible, aperiodic and positive recurrent | Convergence to a unique stationary distribution |
| Reversible | Satisfies detailed balance | Simplifies the design of MCMC samplers |
For an ergodic chain, the distribution of states converges to π from any starting point, and time averages along a single long run equal expectations under π. This ergodic theorem is exactly what Markov chain Monte Carlo relies on to estimate posterior expectations from samples.
The speed of convergence is described by the mixing time, which is closely related to the spectral gap, the difference between 1 and the second-largest eigenvalue modulus of P. A small spectral gap means slow mixing and strongly correlated samples.
Variants of the Markov chain
Several model families extend the basic chain by changing the time index, the order of memory or what is observed. Each variant keeps the Markov property in some form while adapting it to a different modeling need.
| Variant | Key difference | Typical use |
|---|---|---|
| Higher-order chain | Next state depends on the last k states | n-gram language models |
| Continuous-time chain | Transitions occur at random times | Queueing and reliability models |
| Hidden Markov model | States are latent, only emissions are observed | Speech, sequence labeling, genomics |
| Markov decision process | Transitions depend on chosen actions | Reinforcement learning |
| Absorbing chain | Some states cannot be left once entered | Customer churn and time to failure |
A higher-order chain can always be rewritten as a first-order chain over tuples of states, but the state space then grows exponentially with the order, which is the core data-sparsity problem of classic n-gram models.
Markov chains compared with related probabilistic models
A Markov chain models a single observed sequence with first-order dependence, whereas neighboring models in the Topic add latent variables, undirected structure or inference machinery. Knowing the boundaries avoids using a chain where a richer model is required.
| Model | Structure | Main question answered |
|---|---|---|
| Markov chain | Directed sequence of observed states | How do states evolve over time |
| Hidden Markov model | Latent chain plus observation model | Which hidden states explain the data |
| Markov random field | Undirected graph with local dependencies | How are neighboring variables jointly distributed |
| Dynamic Bayesian network | Factored state across time slices | How do many variables evolve together |
| Markov chain Monte Carlo | Chain designed to target a distribution | How to sample from a complex posterior |
In MCMC, the logic is reversed: instead of estimating P from data, algorithms such as the Metropolis-Hastings algorithm and Gibbs sampling construct P so that its stationary distribution equals the posterior of interest.
Estimating and applying Markov chains in practice
Transition probabilities are usually estimated by maximum likelihood, which reduces to counting transitions between each pair of states and normalizing each row. With sparse data, additive smoothing or a Dirichlet prior prevents unseen transitions from receiving a probability of exactly zero.
- Define states carefully, because a poorly chosen state space violates the Markov property in practice.
- Test the memoryless assumption by comparing first-order and higher-order fits.
- Check stationarity of P over time before using one matrix for forecasting.
- Run convergence diagnostics, such as the Gelman-Rubin statistic, when the chain is used for sampling.
Limitations and common misconceptions
The main limitation is the short memory assumption. Natural language, user behavior and financial series often have long-range dependencies that a first-order chain cannot capture, which is why transformers replaced n-gram models for language modeling.
A frequent misconception is that the Markov property means future states are independent of the past. They are dependent, but conditionally independent given the present. Another mistake is assuming every chain converges; a periodic or reducible chain may never reach a unique long-run distribution.
In simple terms
A Markov chain is a way to describe things that move between situations by chance. The key rule is simple. Where you go next depends only on where you are now.
Think of a board game played with a die. Your next square depends on your current square and the roll. It does not matter how you got there. With that rule, computers can predict how often each situation will occur over a long time.
A practical example
A subscription streaming service wants to forecast how customers move between plans. Analysts define four states: free trial, basic, premium and canceled, with canceled as an absorbing state. From twelve months of billing records, they count monthly transitions and estimate a 4 by 4 transition matrix.
The matrix shows, for example, that about 6 percent of basic subscribers cancel each month, while premium subscribers cancel at roughly half that rate. Using the absorbing-chain formulas, the team computes the expected number of months before cancellation for each starting plan. The results guide a retention offer aimed at basic subscribers in their third month, where the estimated cancellation risk is highest.