Antibiotics do not create resistance. They select it. A bacterium copies its genome with about one error in a billion at any given site, and an infection routinely contains a billion bacteria β so the mutant that shrugs off the drug is very often present before the first tablet is swallowed, at a frequency of roughly one in a billion, doing nothing, slightly outcompeted by its neighbours. What the antibiotic does is kill everything else and hand it an empty world.
It is not on or off. Every strain has a minimum inhibitory concentration β the least drug that stops it growing β and resistance means that number is higher, not infinite. The strain here has an MIC thirty-two times the ordinary one, which is a typical single-mutation step. Both curves have exactly the same shape; the resistant one is simply shifted right. Notice what that implies: a high enough concentration still kills the resistant strain, and a low enough one fails to kill either.
If each division has a chance Β΅ of producing the mutation, then after N divisions the chance that no resistant cell exists is (1 β Β΅)N, and the chance one does is one minus that. At a mutation rate of one in a billion the numbers are brutal: a million bacteria give you a one-in-a-thousand chance, but a billion β an unremarkable infection β give you 63 per cent, and a trillion make it a certainty. The curve is not gentle. Almost all of the transition happens across two decades of population size. Drag the mutation rate down to 10−18 and the curve flattens onto the floor β that is not a broken slider, it is what happens when resistance needs two independent mutations instead of one, and it is the whole reason tuberculosis is treated with three or four drugs at once rather than the best one.
| bacteria present | roughly | expected resistant cells | chance at least one exists |
|---|
Now run it. The infection grows for two days before treatment starts, the drug rises and falls with each dose, and the two populations respond differently. Whether a resistant mutant appears at all is genuinely random here β drawn from the same probability as section 2 β so move the seed slider and you are looking at different patients with identical infections and identical treatment. Some of them get away with it. Watch what the immune system does at the end: the drug never finishes the job, it only pushes the population low enough that the immune system can.
There is a band of concentration that is the worst possible place to be: above the ordinary MIC, so sensitive bacteria are being killed, but below the resistant MIC, so resistant ones are not. Inside that band the drug is actively selecting for resistance β it is doing the work of clearing out the competition. Pharmacologists call it the mutant selection window. At 500 mg every eight hours this drug spends one hundred per cent of the time inside it. Push the dose up past the resistant MIC and the window closes.
One run tells you nothing; this runs the whole simulation sixty times per point and counts outcomes. Two things are unambiguous. Courses that are too short do not cure β the drug knocks the population down but not below the level the immune system can finish, so it grows straight back. And under-dosing or spacing doses too far apart is worse than either, because the concentration spends its time in exactly the band that selects resistance without clearing the infection. What is not in this chart is any penalty for treating too long, which is something the model cannot see and the evidence says is real.
The probability law in section 2 is exact and is the heart of this lab: at Β΅ = 10β»βΉ the chance of at least one resistant cell is 0.001000 at N = 10βΆ, 0.632121 at N = 10βΉ and 1.000000 at N = 10ΒΉΒ². It is computed with log1p and expm1, and it is worth being precise about why, because at Β΅ = 10β»βΉ the obvious 1 β (1βΒ΅)^N is perfectly fine β it agrees to about one part in 10βΈ, far beyond anything shown. The naive form only starts to fail further down: it is wrong in the fifth decimal at Β΅ = 10β»ΒΉΒ², and at Β΅ = 10β»ΒΉβΆ and below it collapses completely, because 1 β Β΅ rounds to exactly 1.0 in double precision and so the formula returns a flat zero. That matters here rather than being trivia, because the slider reaches 10β»ΒΉβΈ β the effective rate when resistance needs two independent mutations, which is the entire basis of combination therapy. The honest answer there is a probability of 1.0 Γ 10β»βΉ per infection: small, but not zero, and across enough patients it happens. The naive formula reports that it is impossible. The pharmacokinetics are a standard one-compartment model with first-order absorption and elimination, and the concentrations it produces are used everywhere else on the page rather than being drawn separately. The mutant selection window in section 4 is measured off that curve: at 500 mg every eight hours the concentration is inside the window 100 per cent of the time, at 1000 mg it is 79.1 per cent, and at 4000 mg it is 0. Whether a mutant appears is drawn from a Poisson distribution with the right mean, using a seeded mulberry32 generator, so the same seed always gives the same patient. Small resistant populations are followed as whole cells with random births and deaths, because a model that lets a third of a bacterium survive gives nonsense answers to exactly the question this lab is asking.
The rest is a teaching model with chosen numbers. Growth rates, the immune response, the fitness cost of resistance and the shape of the kill curve are plausible rather than measured, and the absolute percentages in section 5 would move if any of them did β with sixty runs a point, the sampling error alone is about six percentage points, so read the shapes and not the digits. The immune response here saturates, which is what makes a cure possible at all, and it is a caricature of something enormously more complicated. Real resistance is often not a point mutation but a whole gene arriving on a plasmid from another species entirely, which no mutation rate predicts. And one honest correction to the message you were probably given: the evidence that finishing the course prevents resistance is much weaker than the slogan suggests. For many infections, shorter courses work as well and expose the bacteria you are not treating β the ones in your gut and on your skin β to fewer days of selection. This model contains only the infection, so it can show you why stopping too early fails, but it cannot show you the cost of carrying on too long, and that cost is real.