HTML5 game publishing
Idle Game Math: Cost Curves, Big Numbers, Offline Progress and Prestige
Exponential costs against linear income, buying many at once with the geometric series, number formatting, capped offline earnings, prestige formulas and simulating your balance.
Idle and clicker games run on a small set of equations, and most of them go wrong in the same way: the numbers either grow too slowly to feel rewarding or too quickly to need any decisions. The math is not complicated, but it has to be chosen on purpose. This post covers cost curves, income curves, big-number display, offline progress and the "prestige" reset, with the formulas used by most successful games in the genre.
The core loop: cost grows faster than income
Every idle game has generators: things you buy that produce currency over time. Each time you buy another of the same kind, the price goes up by a fixed percentage. The standard formula:
cost(n) = baseCost * growth ** n
where n is how many you already own. A growth factor between about 1.07 and 1.15 is typical, with 1.15 common for generators in many well-known games. A larger factor makes each purchase hurt more and forces you to buy different things. A smaller one lets the player buy the same thing for a long time.
Income is linear in count: income = count * baseIncome. That asymmetry, exponential cost against linear income, is the whole reason progress slows and the player is pushed to the next tier.
Buying many at once
Players want buttons for "buy 10" or "buy max". The sum of a geometric series gives the cost of buying k items without a loop:
function costForMany(base, g, owned, k) {
return base * g ** owned * (g ** k - 1) / (g - 1);
}
function maxAffordable(base, g, owned, money) {
// solve base*g^owned*(g^k - 1)/(g - 1) <= money for k
const k = Math.floor(Math.log(money * (g - 1) / (base * g ** owned) + 1) / Math.log(g));
return Math.max(0, k);
}
This works in constant time, which matters once you own thousands of an item and a loop would be wasteful. Compute with floating point, but be careful near the limits. Round results, and verify the final purchase against the actual cost before deducting.
Tiers: each generator feeds the one below
To avoid a flat game, tier your generators. Tier 2 produces tier 1 units, and tier 1 produces currency. That gives polynomial growth rather than linear, and it makes the game feel like it is accelerating. Keep the tier count to a handful at the start and unlock more as the player progresses. Show only what is relevant so the screen does not become a wall of buttons.
Display big numbers
JavaScript numbers are 64-bit floats. They represent integers exactly only up to about 9 × 1015, and they overflow to Infinity around 1.8 × 10308. Idle games routinely go past both. Options:
- Stay under the limit by design. Many games never exceed 1020 or so, where floats are accurate enough that no one notices small errors. This is the simplest choice.
- Use a big-number library for games that go to 101000 and beyond. It costs speed, so only use it if you must.
- Store as mantissa and exponent yourself for a light version.
Format for display with suffixes or scientific notation:
const SUFFIX = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi'];
function fmt(n) {
if (n < 1000) return n.toFixed(n < 10 ? 2 : 0);
const tier = Math.min(SUFFIX.length - 1, Math.floor(Math.log10(n) / 3));
return (n / 1000 ** tier).toFixed(2) + SUFFIX[tier];
}
Switch to scientific notation past your suffix list, and never show a raw 20-digit number.
Offline progress
The signature feature of idle games is earning while away. The calculation is simple:
const away = Math.min(Date.now() - save.lastSeen, MAX_OFFLINE_MS);
const gain = incomePerSecond * away / 1000 * OFFLINE_RATE;
Three design decisions hide in these lines:
- A cap. Do not credit more than a few hours, or days at most. Otherwise players leave for a week and return to a broken economy.
- A rate below 1. Many games give 50 to 100 percent of online income offline. A lower rate rewards active play.
- Use a trusted clock when it matters.
Date.now()follows the device clock, which players can change. For a casual game that is fine. For anything with a real consequence, decide whether you care.
Save the timestamp regularly and on visibility change, as described in saving progress in an HTML5 game, and version the save so you can rebalance later without breaking old saves. See save data versioning.
Also handle tabs in the background. Browsers throttle timers in hidden tabs, so do not accumulate income by counting ticks. Compute from elapsed time instead of "number of frames", so a throttled tab does not lose progress.
Prestige: a reset that makes the next run faster
When progress slows to a crawl, a prestige system lets the player reset in return for a permanent bonus. A common formula for the bonus currency is a root of lifetime earnings:
prestigePoints = Math.floor(Math.sqrt(lifetimeEarnings / 1e6));
multiplier = 1 + prestigePoints * 0.05;
A square or cube root keeps gains growing without exploding. Show the player what they would gain before they reset, and warn clearly about what is lost. A prestige that surprises players is a fast way to get bad reviews.
Balancing with a simulation
You cannot balance an idle game by feel. Write a script that simulates a player who always buys the cheapest next upgrade and see how long each stage takes. Aim for early purchases every few seconds, a first meaningful goal in minutes, and a first prestige in around an hour. Then adjust growth factors until the curve feels right. The principle is the same one as in solver-checked difficulty: let a program tell you what the numbers do.
Be honest about monetization
Idle games lean on rewarded ads, such as "double your offline earnings". A rewarded ad must only grant the reward in the reward callback, and the game must still work if no ad is available. See granting rewards only in onReward. For how existing idle games on PlayKovo feel, see our idle and clicker roundup.


