Skip to content
Omnikalc

Markov chain calculator: long-run shares and probability after n steps

Enter the switching probabilities between two states and a starting point to get the steady state, the probability after n steps and the mean return time.

Updated on
Your inputs

Value out of range

Value out of range

%

Value out of range

Value out of range

Results

Long-run share of time in state A

25.0%

Long-run share of time in state B
75.0%
Probability of being in state A after n steps
30.83%
Probability of being in state B after n steps
69.17%
Second eigenvalue (speed of convergence)
0.600
Steps to get within 1 % of the long-run share
9
Mean return time to state A
4.00 steps
Mean time to leave state A
3.33 steps

Will tomorrow be sunny if today is rainy? Will a customer be active next month? A Markov chain answers such questions with a simple rule: the chance of the next state depends only on the present one. This calculator handles the two-state case. From the chance of switching from A to B and from B to A it gives the long-run share of time in each state, the probability after n steps, the speed of convergence and the mean return time.

How the calculation works

With switching probabilities p (A to B) and q (B to A):

  • Steady state: share in A = q ÷ (p + q); share in B = p ÷ (p + q)
  • After n steps: P(A) = steady share + (start − steady share) × (1 − p − q)ⁿ
  • Second eigenvalue = 1 − p − q, the factor by which the gap closes each step
  • Mean return time to A = 1 ÷ steady share of A
  • Mean time before leaving A = 1 ÷ p

Example

A system starts in state A (100 %) and moves A to B with probability 0.3 and B to A with probability 0.1 at each step. The long-run shares are 25 % in A and 75 % in B. After 5 steps the probability of being in A is 0.25 + 0.75 × 0.6⁵ = 30.83 %. The convergence factor is 0.6, and it takes 9 steps to come within 1 % of the long-run share. It returns to A every 4 steps on average, and stays in A for 3.33 steps before leaving.

Why it matters

Markov chains are the base of weather models, queueing theory, page ranking, customer retention and many simulation methods. The two-state case shows the ideas without matrices: the steady state, the speed at which the start is forgotten and the average time spent in each state. These give quick answers to planning questions such as how many machines will be down on an average day.

Good to know

The chain must be able to move between the two states (both probabilities above zero) for a steady state to exist. If p + q = 1, the chain forgets its start after a single step, and if p + q is close to 2 it flips back and forth. The model has no memory, so a streak of rainy days is not captured. This tool is for education.

In practice

Estimate p and q from data: p is the number of A-to-B moves divided by the number of times the system was in A, and q the same for B. Compare the steady shares with the observed shares to see whether the Markov assumption holds.

The queue wait time calculator, the probability calculator and the expected value calculator cover related ideas.

Frequently asked questions

What is a Markov chain?

A Markov chain is a model of a system that hops between states, where the chance of the next state depends only on the current state and not on the past. Weather (sunny or rainy), a customer who stays or leaves, or a machine that is up or down can all be modelled this way.

What is the steady state?

It is the share of time the chain spends in each state in the long run, whatever the starting point. For a two-state chain with switching probabilities p (A to B) and q (B to A), the share in A is q ÷ (p + q).

How fast does it converge?

The distance to the steady state shrinks by the factor (1 − p − q) at each step. The closer that factor is to zero, the quicker the chain forgets its start. A factor near 1 means a slow, sticky chain.

What are the limits of the model?

The chain assumes constant probabilities and no memory. Real systems have trends, seasons and memory, so the result is a first approximation. A chain with more than two states needs a matrix calculation.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.