Gambler's Ruin Calculator
The gambler's ruin problem is a classical result in probability theory. A player starts with a stake, bets one unit per round, and continues until they either reach a target or lose everything. This calculator computes the probability of reaching the target before ruin, the complementary probability of going broke, and the expected number of bets until the game ends. It handles both the fair game, where the probability of winning each bet is one half, and the biased game, where any house edge makes long runs increasingly likely to end in ruin.
Gambler's ruin formula
Fair game (p = 0.5): P(reach N) = i / N
Biased game: let r = q / p where q = 1 - p
P(reach N) = (1 - r^i) / (1 - r^N)
P(ruin) = 1 - P(reach N)
Expected bets (fair) = i * (N - i)
Expected bets (biased) = i / (q - p) - N / (q - p) * (1 - r^i) / (1 - r^N)
The target N must be greater than the starting units i, and p must be strictly between 0 and 1.
Random walk context
- In a fair game the probability of reaching the target is exactly the ratio of starting units to the target.
- Any unfavorable edge (p below 0.5) makes r greater than 1, so reaching a high target becomes very unlikely.
- A favorable edge (p above 0.5) makes ruin unlikely but never impossible for finite stakes.
- The expected number of bets is largest for fair games and shrinks as the edge grows in either direction.
- This is a one-dimensional random walk with absorbing barriers at 0 and N.
Gambler's ruin: frequently asked questions
What is the gambler's ruin problem?
A player starts with i units and bets one unit at a time, winning with probability p and losing with probability q = 1 minus p. They stop when they reach a target of N units (success) or reach 0 units (ruin). The gambler's ruin formula gives the probability of reaching N before hitting 0.
What is the formula for the probability of success?
If the game is fair (p equals 0.5) the probability of reaching N before 0 is simply i divided by N. If the game is biased, let r = q/p; then the probability is (1 minus r to the power i) divided by (1 minus r to the power N). The probability of ruin is one minus the probability of success.
How is the expected number of bets calculated?
For a fair game the expected duration is i times (N minus i). For a biased game it is i divided by (q minus p) minus N divided by (q minus p) times (1 minus r to the power i) divided by (1 minus r to the power N), where r = q/p. The calculator handles both cases automatically.
Why does a small house edge almost guarantee ruin over time?
When p is below 0.5 the ratio r = q/p exceeds 1, so r to the power N grows very large as the target N increases. The probability of reaching a high target before ruin shrinks toward zero. This is the mathematical reason that betting against an edge for long enough tends to end in ruin.
What inputs does this calculator need?
Enter your starting units i, the target units N (which must be greater than i), and the probability p of winning a single one-unit bet, between 0 and 1. The calculator returns the probability of reaching the target, the probability of ruin, and the expected number of bets.
Official sources
- U.S. NIST/SEMATECH e-Handbook of Statistical Methods: Engineering Statistics Handbook, probability fundamentals.
- U.S. National Institute of Standards and Technology: NIST home, statistical references.
Reviewed by the CalculatorHub team, edited by James Graham, 17 June 2026. See our methodology.