The formula is a weighted average, and the weights are the probabilities. To compute E(X) = Σ x·P(x) you multiply each value the variable can take by the probability of taking it, and add the products. The reason this is the right definition, rather than an arbitrary one, is worth seeing concretely. Suppose you play a game 1,000 times and outcome x happens on about 1,000·P(x) of them. Your total winnings are about Σ x·1000·P(x), so your winnings per play are about Σ x·P(x). The expected value is nothing more exotic than the ordinary average of a very long run, computed in advance from the probabilities instead of afterwards from the data. That is why it is also written μ and called the mean of the random variable: it is the same idea as the mean of a data set, with relative frequencies replaced by probabilities. Three consequences follow immediately, and each one is examined by the simulation on the left. First, E(X) need not be a value X can ever take. Play the dice game and the expected value is exactly $0.00, yet every single play returns +$8, +$2, or −$4 — never zero. The average family really can have 1.9 children. An expected value is a balance point, not a prediction of any one play. Second, the long-run average converges to E(X) but is not obliged to arrive on schedule. This is the law of large numbers, and the four traces show its actual shape: violent swings over the first few dozen plays, a visible funnel narrowing as the plays accumulate, and every player eventually pressed toward the same horizontal line. The width of that funnel is σ/√n, the standard error, which is why the shaded band tightens in proportion to the square root of the number of plays — quadrupling the plays halves the band. Third, E(X) says nothing about risk. Two games can share an expected value and feel nothing alike; that is what the standard deviation column is for, and why the insurance policy, with an expected value of a few hundred dollars, carries a standard deviation of several thousand. A fair game is defined as one with E(X) = 0, and almost no commercial game is fair. The house edge is simply −E(X) expressed as a fraction of the stake, which is why a 5.26% edge on American roulette means that every dollar staked is worth about 94.7 cents the moment you place it — a number you can read directly off the computation table, and one that no betting system, streak, or choice of number can change.
Six ways this goes wrong. First, reading E(X) as a forecast of the next play. "The expected value is −$0.53, so I'll lose about fifty cents" is wrong on the very next spin, where you will lose $1 or win $35 and nothing in between. E(X) describes the average of many plays, not the result of one. Set the plays slider to 10 and press the play button a few times: the running averages end up scattered all over the chart, and several players finish well ahead. Second, believing the average must arrive quickly, or that a losing streak makes a win "due." The plays are independent; the wheel has no memory of the last thirty spins and no obligation to repay them. The running average does not approach E(X) because losses are compensated by later wins. It approaches E(X) because early results, good or bad, are progressively diluted by the plays that follow — divided by an ever-larger n. Watch the histogram at 2,000 plays: the whole pile has slid left of zero, not because anyone was punished, but because the small per-play deficit has been added up two thousand times. Third, confusing the prize with the payoff. The x in Σ x·P(x) must be the net change in your money. A raffle ticket costing $5 that wins a $300 prize is a net gain of $295, not $300, and the losing outcome is −$5, not $0. Forget to subtract the stake and every expected value you compute is too high by exactly the price of playing. Fourth, assuming a huge prize rescues a tiny probability. Open the lottery and look at the first chart: the jackpot rectangle is a hairline, because a one-in-a-million chance is a width of one millionth. Its area — its contribution to E(X) — is 2.5 cents. Multiplying a very large number by a very small one does not reliably produce a large number, and the intuition that says otherwise is what sells tickets. Fifth, concluding that a negative expected value always means "don't." Buying insurance has a negative expected value by construction; if it did not, no insurer could pay its staff. You buy it anyway because the policy is not a bet you are trying to win, it is the removal of a loss large enough to be ruinous, and avoiding ruin is worth more than the couple hundred dollars a year it costs on average. Expected value is the correct tool for pricing a repeated, survivable gamble, and an incomplete tool for a one-shot decision where the downside is catastrophic. Sixth, treating a positive result over a short run as evidence the edge is beatable. The percentage of players finishing ahead in the histogram is frequently large at 50 plays and shrinks steadily as the plays increase. Being ahead is common in the short run and rare in the long run, and the long run is the only run in which the expected value describes anybody.