Why do species not adapt to ever-wider ranges of conditions, gradually expanding their ecological niche and geographic range? Gene flow across environments has two conflicting effects: although it increases genetic variation, which is a prerequisite for adaptation, gene flow may swamp adaptation to local conditions. In 1956, Haldane proposed that, when the environment varies across space, "swamping" by gene flow creates a positive feedback between low population size and maladaptation, leading to a sharp range margin. However, current deterministic theory shows that, when variance can evolve, there is no such limit. Using simple analytical tools and simulations, we show that genetic drift can generate a sharp margin to a species' range, by reducing genetic variance below the level needed for adaptation to spatially variable conditions. Aided by separation of ecological and evolutionary timescales, the identified effective dimensionless parameters reveal a simple threshold that predicts when adaptation at the range margin fails. Two observable parameters determine the threshold: (i) the effective environmental gradient, which can be measured by the loss of fitness due to dispersal to a different environment; and (ii) the efficacy of selection relative to genetic drift. The theory predicts sharp range margins even in the absence of abrupt changes in the environment. Furthermore, it implies that gradual worsening of conditions across a species' habitat may lead to a sudden range fragmentation, when adaptation to a wide span of conditions within a single species becomes impossible.W hy a species' range sometimes ends abruptly, even when the environment changes smoothly across space, has interested ecologists and evolutionary biologists for many decades (1-8). Haldane (2) proposed that, when the environment is spatially heterogeneous, a species may be unable to adapt and expand its range because gene flow from the center swamps the populations at the range margins, preventing their adaptation. Theory showed that, when genetic variance is fixed, adaptation indeed fails if the environment changes too steeply across space (9), and a sharp margin to the species' range forms. The population remains well adapted only in the center of the range, and gene flow swamps variants adapted to the margins, preventing range expansion. This result also elucidates range margins in the presence of competitors: then, interspecific competition in effect steepens the environmental gradient (10). However, this limit to adaptation assumes that local genetic variation is fixed. Current deterministic theory states that, when genetic variance can evolve, there is no sharp limit to a species' range (11). The genetic mixing caused by gene flow inflates the genetic variance and facilitates further divergence. Gene flow across a phenotypic gradient maintained by the environment can generate much more variance than would be maintained by mutation alone (12,13). This rise of genetic variance with environmental gradient can allow species to adapt to ...