Home / Operations Research / Markov Chain Calculator
Operations Research & Stochastic Models
Markov Chain Calculator
In short: a Markov chain moves between states with step-to-step probabilities. Enter a transition matrix below and this tool returns the steady-state distribution, the distribution after n steps, a full state classification, and, for absorbing chains, the expected steps to absorption and the probability of each ending.
Solve a Markov chain
transition matrix → steady state, state classification, and (if absorbing) time and probability of absorption
Steady-state distribution
Brand A 43.5% · Brand B 37.0% · Brand C 19.6%
Enter a transition matrix to analyse the chain.
What a Markov chain models
A Markov chain describes a system that moves between a finite set of states one step at a time, where the only thing that governs the next state is the current one.
That single assumption, that the future depends on the present but not on the path that led there, is the Markov property, and it is enough to build a model that forecasts where the system will be far into the future, finds the long-run balance it settles into, and measures how long processes take to finish.
The whole model lives in one object, the transition matrix: a square grid whose entry in row i and column j is the probability of stepping from state i to state j, with each row adding up to one because the system always goes somewhere.
The reason this small idea reaches so far is that a surprising number of real systems are, to good approximation, memoryless at the level of states. A customer is active, lapsed, or churned; a machine is running, degraded, or failed; a loan is current, late, defaulted, or paid off; a brand holds a customer or loses them to a rival.
In each case the next state is well predicted by the current one, and the history matters mostly through where it left the system now.
Once you accept that framing, the transition matrix captures the dynamics, and a handful of standard calculations answer the questions people actually ask: what is the long-run share, how long until this ends, and what are the odds of each ending.
This calculator takes any transition matrix you type and does that standard analysis for you. It finds the steady-state distribution the chain converges to, classifies every state as recurrent, transient, or absorbing and reports its period, forecasts the distribution after any number of steps from a starting point you choose, and draws how the state probabilities converge step by step. When it detects an absorbing chain, it switches to the analysis that matters there and reports the expected number of steps to absorption and the probability of ending in each absorbing state. Everything runs in your browser, and nothing you enter is stored.
How to use this calculator, step by step
Start with the transition matrix. Type it one state per row, with the probabilities of moving to each state separated by spaces or commas, keeping the states in the same order across every row. Each row must add up to one, since from any state the system is certain to move somewhere; the calculator checks this and tells you which row is off if a row does not sum to one. The tool opens with a solved three-state brand-switching example so you can see a complete result, the long-run market share of three brands, before you change anything.
You can optionally name the states in the second box, comma-separated, so the results read as Brand A, Running, or Current rather than S1, S2, S3. The third box holds an initial state vector, which is where the chain starts for the step-by-step forecast; leave it and the tool assumes the chain begins in the first state. The last box sets how many steps ahead to forecast. As soon as the matrix is valid the calculator solves live, so editing a probability or a label updates every result and the chart immediately.
The result panel leads with the headline, the steady-state distribution for an ordinary chain or an absorption summary for an absorbing one. Below it, a table lists each state with its long-run probability, its classification, and its period, and a set of chips shows the distribution after your chosen number of steps. For an absorbing chain two extra tables appear: the expected steps to absorption from each transient state, and the probability of ending in each absorbing state. A convergence chart plots each state probability across the steps so you can watch the approach to the long run, and you can download the results as PDF or CSV or share them.
Reading the transition matrix and the steady state
The transition matrix is worth pausing on because everything else is derived from it. Each row is a state you are currently in, and reading across that row gives the probabilities of where you will be next. A diagonal entry is the probability of staying put; a large diagonal means a sticky state the system tends to hold, while a small one means the system rarely lingers. Because each row is a full set of possibilities, it must sum to one, and this is the single most common data-entry mistake, a row that sums to slightly more or less than one, which is why the calculator validates it explicitly.
The steady-state distribution answers the long-run question. Formally it is the probability vector pi that satisfies pi P = pi, meaning that once the system reaches this distribution, applying another step leaves it unchanged; the proportions have stopped moving even though individual members keep switching states.
For an ergodic chain, one that is irreducible and aperiodic, this distribution is unique and the system converges to it regardless of where it started, which is exactly why it can stand for long-run market share, long-run machine occupancy, or the long-run fraction of time in any state.
The calculator solves pi P = pi as a linear system and normalises the answer to sum to one, falling back to repeated multiplication if the direct solve is ill-conditioned.
It helps to separate the steady state from the starting point. The initial vector and the step count answer a different, shorter-horizon question: given where the system is now, where will it be after n steps? Early on this transient distribution can look nothing like the steady state, and the convergence chart shows it sliding toward the long-run values step by step. Both views are useful: the n-step forecast for planning a few periods ahead, the steady state for the long-run balance. Reading them together is often more informative than either alone, because it shows not just where the system ends up but how quickly it gets there.
Ergodic chains and absorbing chains: two different questions
Markov chains split into two broad types that call for different questions, and the calculator recognises which one you have entered. An ergodic chain keeps moving among all its states forever; it never gets stuck, and the interesting result is the steady-state distribution, the long-run share of time in each state. Brand switching where customers keep changing, weather that keeps cycling, a machine that is repaired and returns to service, all of these are ergodic, and their story is told by the stationary distribution and how fast the chain converges to it.
An absorbing chain is different because it has states that, once entered, are never left. These model processes that end rather than cycle: a customer who churns for good, a loan that is paid off or written off, a game that is won or lost, a patient who is discharged.
For such a chain the steady-state question is almost trivial, in the long run the system is absorbed with certainty, so the useful questions become how long until it ends and which ending is it. Those are exactly the results the calculator produces for an absorbing chain: the expected number of steps to absorption from each transient state, and the probability of finishing in each absorbing state.
It detects the absorbing states automatically, from the rows whose probability of staying is one, and switches its output to match.
Knowing which type you have is the first analytical step, because it decides which numbers matter. If your process genuinely never ends, read the steady state. If it has definite terminal outcomes, the absorption results are the payoff, and the steady state on its own would be a distraction. Many real models are mostly ergodic with one or two absorbing states bolted on, for example a customer-state model where every active state can eventually reach a permanent churn; the calculator handles those by treating the churn state as absorbing and reporting how long customers last and how likely each ending is.
Five worked examples you can follow
Example 1: long-run market share
The calculator opens with a three-brand switching model. Each row gives the probability that a customer of one brand this period buys each brand next period, and the diagonal, the largest entries, captures loyalty. The steady-state result, roughly 43.5% for Brand A, 37.0% for Brand B, and 19.6% for Brand C, is the long-run market share the system converges to no matter which brand you start a customer in. Change a single loyalty or switching probability and watch the long-run shares shift, which is the fastest way to see how retention drives share more than acquisition does.
Example 2: a short-horizon forecast
Keep the same matrix but read the distribution after n steps instead of the steady state. Starting every customer in Brand A and stepping forward, the distribution slides from all-A toward the steady state; after ten periods it is already close but not identical to the long-run share. This is the practical difference between where a segment is now and where it is heading, and the convergence chart makes the speed of that approach visible, which matters when you plan only a few periods ahead rather than to infinity.
Example 3: an absorbing customer-churn model
Add a churn state that customers can enter but never leave, giving it a row that is one on its own diagonal, and make the active states able to reach it. The calculator now detects an absorbing chain and reports the expected number of periods before a customer churns from each active state, and, if you have more than one terminal outcome, the probability of each. Expected steps to absorption is a clean estimate of customer lifetime in periods, derived straight from the switching probabilities rather than assumed.
Example 4: the gambler’s ruin random walk
A classic teaching chain: a gambler with some money bets one unit repeatedly, states are the current fortune, and the two ends, broke and target, are absorbing. Enter the up and down probabilities on the interior states and ones on the two ends. The calculator returns the probability of reaching the target before going broke from each starting fortune, which for a fair game equals the starting fraction of the target, and the expected number of bets before the game ends. It is a compact way to see absorption probabilities and expected duration in one familiar model.
Example 5: a small chain you can check by hand
Try a two-state chain such as a machine that is up or down, with simple round probabilities you can verify. Solve pi P = pi on paper and confirm the calculator matches, then read the period column to confirm both states are aperiodic. A two-state chain is small enough to check completely, which builds confidence before you trust the tool on a larger matrix where hand calculation is impractical. Nudging one probability and re-solving shows how sensitive the long-run balance is to the transition rates.
Three expert tips for a clean analysis
Make every row sum to one
Each row is a complete set of next-step probabilities, so it must total one. A row that sums to 0.99 or 1.02 is the usual entry error; the tool flags the offending row so you can fix it before reading results.
Decide ergodic versus absorbing first
If the process cycles forever, read the steady state. If it has states it never leaves, read the absorption results. Knowing which question applies keeps you from quoting a number that does not answer it.
Check the period column
A period above one means the chain cycles and has no single resting distribution. Read its long-run figures as time-averages, and be wary of a steady state for a strictly periodic chain.
The mathematics behind the results
The calculations are worth understanding even though the calculator does the arithmetic. The n-step forecast is pure matrix multiplication: if the current distribution is a row vector x, then after one step it is x times P, after two steps x times P squared, and after n steps x times P to the n.
The tool uses fast exponentiation so even a large number of steps is instant.
The steady state is the vector pi that this multiplication no longer changes, pi P = pi, which is a system of linear equations; combined with the requirement that the probabilities sum to one, it has a unique solution for an ergodic chain, and the tool solves it directly by Gaussian elimination, using repeated multiplication as a fallback.
The absorbing analysis rests on the fundamental matrix. Reorder the states so the transient ones come first, and the transition matrix splits into a block Q of transient-to-transient moves and a block R of transient-to-absorbing moves. The fundamental matrix N is the inverse of the identity minus Q, and its entries count the expected number of visits to each transient state before absorption. From N two results follow immediately.
The expected number of steps to absorption from each state is the sum across that state’s row of N, because total time is the total of expected visits. The probability of being absorbed into each absorbing state is N times R, which distributes the expected path over the possible endings.
The calculator forms Q and R from your matrix, inverts the identity minus Q, and reports both derived results, so the fundamental-matrix method that fills a page of a textbook happens in one click.
State classification uses reachability. Two states communicate if each can be reached from the other through some sequence of steps, and this groups states into classes.
A state is recurrent if every state reachable from it can reach it back, so the chain always returns; it is transient if it can reach a state that cannot return, so there is a chance it never comes back; and it is absorbing if it simply never leaves.
The period of a state is the greatest common divisor of the possible return times, and a period of one means the state is aperiodic. The calculator computes reachability across the whole matrix, labels each state accordingly, and computes each period, which together tell you the structure of the chain at a glance.
Where Markov chains are used
The range of applications is one of the reasons the model is a fixture of operations research. In marketing, brand-switching matrices give long-run market share and show how loyalty and win-back rates drive it.
In customer analytics, states from active through lapsed to churned turn a switching matrix into an estimate of customer lifetime and churn probability.
In finance and credit, ratings that drift between grades and into default are modelled as a Markov chain, and the absorbing analysis gives expected time to default and default probability by starting grade. In operations and maintenance, machine-condition states from running through degraded to failed feed reliability and maintenance planning.
The reach goes further. Weather and demand are often modelled as chains over discrete conditions; inventory and queue levels move between states with step probabilities; disease progression through stages, some of them absorbing, is a natural Markov model in health analytics.
The random walk that underlies web-page ranking is a giant Markov chain whose steady state is the ranking itself, and Markov chain Monte Carlo, a workhorse of modern statistics and machine learning, builds a chain whose steady state is the distribution it wants to sample.
In all of these the same handful of results, the transition matrix, the steady state, the classification, and the absorbing analysis, do the work, which is why learning to read them once pays off across many fields.
Within this toolkit the Markov chain sits in the waiting-lines and stochastic group alongside queuing theory, and the two are close relatives: a queue’s number-in-system is itself a Markov chain over the possible occupancy levels, and the steady-state queue formulas are the stationary distribution of that chain.
Where queuing theory packages the standard arrival-and-service models into ready formulas, the Markov chain calculator handles any state structure you can write as a matrix, which makes it the more general tool when your system does not fit a textbook queue. Return to the Operations Research hub for the full set of models.
Setting up a real system as a chain
Turning a real situation into a Markov chain is mostly about choosing the states well and estimating honest transition probabilities. The states should be a complete and mutually exclusive description of where the system can be, so that at any moment it is in exactly one of them, and they should be defined at a level where the memoryless assumption is reasonable, meaning the next state really is predicted well by the current one. Choosing too few states hides important dynamics; choosing too many makes the probabilities hard to estimate and the model fragile. The art is in picking states that are distinct enough to matter and coarse enough to measure.
The transition probabilities usually come from data. If you have a history of the system moving between states, the probability of going from state i to state j is estimated as the fraction of times that, when in i, it moved to j next, and those fractions naturally form rows that sum to one. When data is thin, probabilities can be judged from expertise, but they should still be checked against whatever history exists, and a row that sums to something other than one is a sign of a counting or rounding error rather than a real feature. The step length matters too: a monthly chain and a weekly chain of the same system have different matrices, and the step must match the horizon you care about.
Finally, decide what you are asking before you read the output. If you want the long-run balance, the steady state is the answer and the initial vector barely matters. If you want a forecast for a specific horizon, set the initial vector to today’s distribution and read the n-step result. If your process ends, mark the terminal states as absorbing and read the expected time and absorption probabilities. Matching the question to the right result is what turns a solved matrix into a decision, and it is worth being explicit about the question first so the numbers you quote are the ones that answer it.
When the simple model does not fit
The Markov chain is deliberately simple, and its simplicity is also its boundary. The core assumption is that the next state depends only on the current one, and when the real system’s future depends on more of its history, the plain chain is the wrong shape. A process where how long you have already been in a state changes the odds of leaving, for example, breaks the memoryless assumption; sometimes you can rescue the model by adding states that encode the extra history, but that grows the matrix and can become unwieldy, at which point a richer model is more honest.
Time is another boundary. This calculator handles discrete-time chains, where the system steps at fixed intervals; systems that change in continuous time, where events can happen at any moment, are modelled as continuous-time Markov chains with transition rates rather than probabilities, a related but distinct tool.
Non-stationarity is a third: if the transition probabilities themselves drift over time, for example because a market is changing structurally, a single fixed matrix describes only a snapshot, and the results should be read as valid while the matrix holds.
None of these caveats diminishes the chain’s value on the many systems that are genuinely discrete, memoryless, and stable; they simply mark the edges where a more elaborate model earns its extra complexity, and recognising your system’s shape before modelling is what keeps the answer meaningful.
Reading beyond the headline number
A solved chain offers more than one number, and the best analysis reads several together. The steady state tells you the destination, but the convergence chart tells you the speed, and a chain that reaches its long run in three steps supports very different planning from one that takes forty, even when their steady states are identical. Watching the chart is the quickest way to judge whether a long-run figure is a fair guide for your actual horizon or whether the transient behaviour dominates the period you care about, and that distinction routinely changes a decision.
The classification and periods deserve attention rather than being skipped. A transient state with a long expected residence can matter a great deal in the medium term even though its steady-state probability is zero, and reading only the steady state would miss it entirely. A period greater than one is a warning that the chain cycles and that its long-run figures are averages over the cycle, not a distribution the system rests in; quoting a steady state for a strictly periodic chain without that caveat is a common and misleading error. The tool surfaces both so you can read them, and the discipline of checking them turns a plausible-looking result into a trustworthy one.
Finally, treat the matrix as an estimate and stress-test the conclusion. If a small change to one transition probability swings the steady state or the expected absorption time sharply, the result is sensitive and your estimate of that probability deserves more care; if the conclusion is stable across reasonable variations, you can trust it more. Re-solving with a few perturbed matrices is quick and tells you how much the decision really rests on the exact numbers, which is often more valuable than the single headline figure the model first hands you.
A brief history of the idea
The model is named for the Russian mathematician Andrey Markov, who introduced it in the early years of the twentieth century, around 1906, while arguing a point in probability theory. The prevailing law of large numbers had been proved for independent events, and a critic claimed independence was essential to it.
Markov set out to disprove that by constructing dependent sequences that still obeyed the law, and to make the argument concrete he analysed the sequence of vowels and consonants in a long poem by Pushkin, treating each letter’s type as a state whose probability depended on the letter before it.
That literary exercise, counting how often a vowel followed a consonant and the reverse, was the first worked example of what we now call a chain, and it established the memoryless dependence that defines the model.
For a few decades the idea remained largely theoretical, a topic in pure probability. Its practical career took off in the middle of the century as operations research matured and computers made the matrix arithmetic routine.
The same structure turned out to describe queues, inventories, reliability, and countless other systems, and later became the engine behind web-page ranking and the simulation methods that power modern statistics and machine learning. It is a striking arc: a construction invented to win an argument about a poem became one of the most widely applied models in science and industry.
Understanding it today means standing on a hundred years of use across fields its inventor never imagined, which is part of why it remains a staple of every operations-research course.
Input format and quick reference
Type the transition matrix one state per row, probabilities separated by spaces or commas, each row summing to one. Optionally name the states and give an initial vector and a step count for the forecast. The reference below explains each part of the result.
| Output | What it means |
|---|---|
| Steady-state probability | The long-run fraction of time the chain spends in that state (pi P = pi) |
| Distribution after n steps | Where the system is n steps from the initial state, x times P to the n |
| Type | Whether the state is recurrent, transient, or absorbing |
| Period | The cycle length of returns; one means aperiodic |
| Expected steps to absorption | For an absorbing chain, the mean number of steps before an end state is reached |
| Absorption probabilities | The chance of ending in each absorbing state from each transient start |
Frequently asked questions
What is a Markov chain?
A Markov chain is a mathematical model of a system that moves between a finite set of states in steps, where the probability of the next state depends only on the current state and not on the history of how it got there. That memoryless property is called the Markov property, and it is what makes the model both simple and powerful. You describe the system with a transition matrix: one row per state, each row giving the probabilities of moving to every state on the next step, with each row summing to one. From that single matrix you can forecast where the system will be after any number of steps, find its long-run behaviour, and answer questions about how long things take.
What is a transition matrix?
The transition matrix is the heart of a Markov chain. It is a square grid where the entry in row i, column j is the probability of moving from state i to state j on the next step. Because from any state the system must go somewhere, every row adds up to exactly one. A three-state chain has a three-by-three matrix, a five-state chain a five-by-five one, and so on. This calculator asks you to type the matrix one row per line; it checks that the matrix is square and that every row sums to one before it solves, and it flags the offending row if a row does not.
What is the steady-state (stationary) distribution?
The steady-state or stationary distribution is the long-run fraction of time the chain spends in each state, written as a probability vector pi that satisfies pi P = pi. For an ergodic chain the distribution the system settles into is unique and does not depend on where it started, which is why it answers questions like the long-run market share of each brand or the long-run occupancy of each machine state. This calculator solves pi P = pi directly as a linear system, and falls back to power iteration if needed, then reports the stationary probability of each state.
What is an absorbing Markov chain?
An absorbing Markov chain has one or more absorbing states, states that once entered can never be left because their probability of staying is one. Every other state is transient and, in a proper absorbing chain, can eventually reach an absorbing state. These chains model processes that end: a customer who churns, a loan that defaults or is paid off, a patient who recovers or does not, a game that is won or lost. This calculator detects absorbing states automatically and, when the chain is absorbing, switches to the analysis that matters there: expected steps to absorption and the probability of ending in each absorbing state.
What is the fundamental matrix?
For an absorbing chain, the fundamental matrix N is defined as N = (I minus Q) to the power minus one, where Q is the part of the transition matrix that describes moves between transient states. Its entry in row i, column j gives the expected number of times the chain visits transient state j before absorption when it starts in transient state i.
From N you get the two most useful results: the expected number of steps to absorption from each starting state, which is the row sum of N, and the probability of being absorbed into each absorbing state, which is N times R where R is the transient-to-absorbing block.
This calculator computes N and both derived results whenever it detects an absorbing chain.
How many steps until the chain reaches its steady state?
A Markov chain approaches its steady state gradually rather than reaching it exactly at a fixed step, so the honest answer is that it converges. How fast depends on the matrix; some chains are close to their stationary distribution within a handful of steps, others take dozens. This calculator lets you set a number of steps and an initial state, then shows both the exact distribution after that many steps and a convergence chart that plots each state probability step by step, so you can see the approach visually and judge how many steps count as good enough for your purpose.
What does the period of a state mean?
The period of a state is the greatest common divisor of the numbers of steps in which it is possible to return to that state. A period of one means the state is aperiodic, which is the usual and well-behaved case; a period of two or more means returns only happen on a fixed cycle, for example every second step, which prevents the chain from settling into a single steady distribution even though long-run averages still exist. This calculator reports the period of each state so you can spot periodicity, because a periodic chain needs its results read as long-run averages rather than as a distribution the system rests in.
What is the difference between a recurrent and a transient state?
A state is recurrent if the chain, starting there, is certain to return to it eventually, and transient if there is a positive probability it never comes back. In the long run the chain spends all its time in recurrent states and none in transient ones, which is why the steady-state probability of a transient state is zero. Absorbing states are a special kind of recurrent state that, once entered, is never left. This calculator labels every state as recurrent, transient, or absorbing, which tells you at a glance which states carry the long-run behaviour and which are only passed through on the way.
Can this handle any number of states?
Yes, within reason. The calculator accepts any square transition matrix you type, from a two-state chain up through large ones, and it solves the steady state, classification, and absorbing analysis for all of them. It reads the matrix from a text box, one row per line with the probabilities separated by spaces or commas, and you can optionally give the states names so the results read clearly. Very large matrices are still solved, though extremely large ones are better handled by dedicated software; for the teaching examples and business models most people bring to a Markov chain, any size you are likely to type works instantly.
What real problems do Markov chains solve?
Markov chains model any system that moves between states with step-to-step probabilities: brand switching and long-run market share, customer states from active to churned, credit ratings drifting between grades and into default, machine condition from running to degraded to failed, weather patterns, inventory and queue states, disease progression, and the random walks behind web-page ranking and many simulations. The steady-state answer gives long-run proportions; the absorbing analysis gives expected time to an end state and the odds of each outcome. Because the same small matrix answers so many different questions, the Markov chain is one of the most reused models in operations research.
Does this calculator store the matrix I enter?
No. The calculator runs entirely in your browser. The transition matrix, state names, and initial vector you type are never sent to our servers, stored, or shared. You can download a PDF or CSV of your results locally, and nothing leaves your device. See our Privacy Policy for details.
Is the Markov chain calculator free?
Yes. The Markov chain calculator is completely free, with no account, sign-up, or usage limit. It returns the steady-state distribution, the distribution after any number of steps, a full state classification with periods, and, for absorbing chains, expected steps to absorption and absorption probabilities, along with a convergence chart and PDF and CSV export at no cost.
Related operations research calculators
More tools in this silo. Return to the Operations Research hub for the full set.
Sources, disclaimer and editorial transparency
This calculator analyses discrete-time finite Markov chains using standard operations-research methods: it solves the stationary distribution from pi P = pi, forecasts n-step distributions by matrix powers, classifies states by reachability and period, and, for absorbing chains, uses the fundamental matrix N = (I minus Q) to the power minus one to compute expected steps to absorption and absorption probabilities. This calculator and guide are created and reviewed by the OpsCalculators team; see our Editorial Policy for how each tool is researched, built, and tested.
Results are accurate estimates for planning and education, not certified engineering advice, and they assume the Markov property holds, that the next state depends only on the current one, and that the transition matrix is stationary over the horizon you apply it to. Validate the matrix against your own data before acting on the results. See our full Disclaimer. OpsCalculators.com is operated by MAFHH INTERNATIONAL LTD. Your data is processed in your browser and never stored; see our Privacy Policy.