Once upon a time, before India knew Asia, when alligators sunned themselves on shores north of the Arctic Circle, a small, timid, dog-like creature tentatively waded into a river. Fifty million years passed. The continents wandered and crashed, and the ocean reconfigured itself.

Now, where there were once Arctic alligators, there was ice. As for the creature who once dipped its toes into the tepid river, it now swam the frigid seas. The intervening age had transformed it into the largest animal in the history of life on Earth.

“There’s a famous paleontologist who’s dead by now, George Gaylord Simpson, and he once described whales as, ‘On the whole, the most peculiar and aberrant of mammals,’” says Felix Marx, a whale paleontologist and Marie Skłodowska-Curie Fellow at Monash University in Melbourne, Australia. “And I think that’s really true, because, I mean, they’re mammals, so they have to face all of the challenges that a normal mammal does. They’re adapted to living on land: they’re [warm-blooded], they have fur, they breathe air, they give birth to live young and they have to suckle those live young. And then you try and do all of that in the sea, and of course, almost everything is stacked against you. Like, the milk is floating away, heat is draining from your body, your fur isn’t really that useful, there’s no air to breathe—like, everything is against you. And yet, within a relatively short period of time they’ve managed to tackle all of that, and they managed to achieve feats like diving down several kilometers and staying down for—I don’t know—an hour at a time, and doing some of the weirdest, biggest feeding events in all of the animal kingdom.”

How they got there, transforming from four-legged, landlubbing also-rans, patrolling Pakistani riverbanks, to the globe-spanning marine colossus of earth’s history is the sort of question that gets people to pursue Ph.D.’s in paleontology in the first place.

“Among mammals, whales really stand out to me for having to have met the most obstacles in their evolution,” says Marx. “They’re really a poster child of evolution.”

The evolution of whales spans whole ages and unfamiliar worlds. It draws from an oeuvre that includes, not only paleontology, but paleoclimatology, oceanography, geology and paleoecology as well. To get a foothold on this dizzying sweep, UC Berkeley Ph.D. candidate Larry Taylor has decided to probe something smaller. Not the whales themselves, but the barnacles that cling to the animals—hitching rides around the planet. As Taylor realized, oxygen isotopes in barnacle shells act as a chemical passport of a whale’s travels, filled with stamps from the world’s various oceans. And humpback-whale barnacles go back millions of years in the fossil record. Taylor hopes to find ancient whale journeys coded in these fossil shells—journeys that could illuminate the evolution of whales and, perhaps even, why some got so preposterously large.

Starting about three million years ago, after a long decline from the high-CO2 greenhouse of the dinosaurs, the earth descended into a waxing and waning low-CO2 ice age—one that continues to this day (albeit precariously). In this ongoing ice age, the planet has swung back and forth between more wintry climes when there was a half-mile of ice crushing Boston and sea levels were 400 feet lower—to warm, but brief, interglacials like today, when the ice sheets temporarily retreat to the poles. And back and forth and back and forth and back again, as the northern hemisphere wobbles in and out of the sunshine. If Taylor’s barnacle data showed ancient whales changing their behavior in response to these climate changes, it might go a long way in explaining why baleen whales in particular (those bristle-mouthed whales that gulp plankton by the ton) have become globe-traveling giants, capable of going months without food—and dwarfing every other animal in the planet’s history.

“Essentially no one knows anything about whale migration in the prehistoric past,” says Taylor. “But the idea would be that as climate got more unstable in the last several million years—and we went through glacial maximums and minimums—the productive zones of the oceans would have been shifting around a lot, and these huge animals could quickly adapt their behavior to find these productive zones of the ocean. Evolution might have favored these really large animals that could migrate huge distances and survive off an enormous fat store.”

It’s an intuitive idea. But it’s long been just that—an idea. This is where Taylor’s humpback barnacles come in. The unassuming shells effectively act as a black box for whale journeys of the distant past.

Here’s the trick. Whale barnacles build their shells from seawater. Seawater, as you might imagine, is made of atoms. Some of those atoms are oxygen. And oxygen in the ocean comes in lighter and heavier isotopes. Water closer to the poles tends to be lighter because most of the heavier stuff—being heavier—has been literally rained out of the clouds in the long trip to the Arctic. This is because, in very general terms, the most evaporation happens where there’s the most sunshine (near the equator) and, as the water evaporates and moves pole-ward, it’s successively rained out, re-evaporated, rained out, re-evaporated, rained out and so on, along the journey north. In the process—with each step—the water is essentially distilled for lighter isotopes. As a result, animals swimming in the Arctic find themselves in lighter water.

Over the seasons, barnacle shells grow in bands from this surrounding seawater. It stands to reason, then, that if the barnacle is moving from ocean to ocean aboard a migrating whale, the shifting isotopes in each growth band laid down will reflect this travel. And so, Taylor sampled his barnacle growth bands and analyzed this changing composition—the wavering chemistry reflecting an animal crossing whole oceans with the changing of the seasons. But this isn’t as easy as it sounds. Confusingly, humpback whale barnacles take in more heavy oxygen isotopes the colder it gets. As a result, the straightforward signal from the ocean is scrambled. But luckily geochemists, in their infinite wisdom, have devised a Greek-alphabet-soup of an equation to unscramble this mess and work back to the original ocean chemistry.

After figuring out the how to unscramble the signal, Taylor mapped this shifting isotope profile onto the modern oceans (an idea that originated with paleontologist J.S. Killingley), giving him an accurate reconstruction of where the barnacle (and the whale) journeyed over its lifetime, moving from higher to lower latitudes—and back again. Simple stuff. The work falls under the umbrella of “stable-isotope geochemistry,” a field whose name suggests a dreadful slog, but one that’s allowed scientists to reconstruct everything from the diets of grizzly bears to the heights of ancient mountain ranges, long eroded-away.

Taylor showed me a graph on his laptop of data from a modern Alaskan humpback barnacle.

“This is consistent with the whales feeding in Alaska,” he said, pointing to the data. “Then, most Alaska humpbacks winter in Hawaii, and—look—when you move down the slope to the fall, these low values are consistent with the animal migrating to Hawaii.”

The atomic inscriptions in other humpback barnacles accurately captured an animal moving from California to Baja. But these measurements (undeniably clever as they are) merely confirm what we already know about whale migration. For Taylor, though, this is just a proof-of-concept. He wants to know where whales were traveling hundreds of thousands, even millions of years ago—if they were even traveling at all. Using the isotopes of fossil barnacles stretching back millions of years, and mapping them onto the ancient ocean, Taylor hopes to find out just what the whales of a bygone Earth were up to.

Of the many “peculiar and aberrant” features of modern baleen whales, perhaps the most peculiar, even to non-scientists, is their tremendous size. It’s difficult not to wonder when considering an animal like the blue whale, whose heart alone weighs 400 pounds: Why is it so outrageously huge? Even Melville puzzled over this trend in whale evolution toward gigantism, noting, in one of those interminable naturalist interludes of Moby-Dick, that “the whales of the present day” were “superior in magnitude” to those of the fossil record. Naturally, evolutionary biologists—ever eager to explain how the tiger got its stripes—have speculated about why whales got so big as well. Perhaps, they say, baleen whales got bigger to go farther.

“The idea is, you need this enormous size and these really powerful tail flukes to get you through these vast ocean basins easily,” Taylor says. It’s a skill that, as mentioned, might have become especially valuable in the past few million years during the chaotic plunge into the ice ages, as food sources became less predictable and animals had to commute across the oceans to seasonal feeding grounds.

These adaptations for epic journeys explain why entanglement with fishing gear is one of the top killers for modern whales. The whales can’t afford any extra drag. Humpback mothers can lose upwards of a third of their body weight during the winter, while nursing North Atlantic right whales can lose 30,000 pounds in the transit between the tropics and their feeding grounds in the northeast. Any additional yoke, like lobster trap groundlines wrapped around your fins—can throw off this monumental caloric calculus, starving migrating whales (70 percent of critically endangered North Atlantic right whales bear the scars of entanglement).

If migration was, in fact, selected for by the ice ages, perhaps the ancient barnacles will say so. But at this point, Taylor says, all of this—the connection between gigantism, migration, and climate history—is little more than a hunch.

“We don’t even know if they were migrating.” he says.

Not all whales faced the turning of the geological seasons with good humor. While giants, like blues and humpbacks, might have escaped the harrowing gauntlet of the past few million years—perhaps by journeying further in search of food—their extended family was sacrificed at the gates of the ice ages. In fact, it was less that baleen whales got big—after all, there existed giant whales before—than that a wild variety of smaller whales was selectively decimated by the planetary chill.

“Gigantism isn’t necessarily something that only occurred in the last 3 million years or so,” says Monash University paleontologist Felix Marx. “But what did change, as far as we can tell, is that all of the little ones suddenly start to disappear. You’ve got a whole range of whales that don’t even exist today.”

Marx had just returned from a fossil-collecting trip to Peru’s Ica desert, where he searched for these ancient whales from the group’s glory days, before the icy scythe of the Pleistocene. While sheer hugeness might seem like an intrinsic feature of baleen whales, the animals once filled out an entire spectrum of shapes and sizes.

“You’ve got all sorts of stuff that’s just a lot smaller—like, three, four, five meters. And about 3 million years ago or so, as far as we can tell, they all disappear.”

When the frost came and the smaller whales vanished, the largest whales stayed on their ballooning trajectory, to the point where, today in the ocean, swims the largest animal in the planet’s history: the blue whale.

“There’s not much evidence that [animals that big] occurred much before 3 million years ago,” he said. “So you’re just left with big stuff.”

If the ice ages selected for gigantic migratory baleen whales, something about the ancient ocean also seems to have also selected against what, to us, would appear as a kaleidoscopic world of runts.

“If you’re a little whale you’re going to be a little bit less wide-ranging,” says Marx. “You’re probably going to be a bit more coastal as well.”

That’s a dangerous lifestyle in a world that’s freezing. Sea levels had soared before the ice ages, and the flooded coastline welcomed smaller whales to spend their lives in the friendly shallows. But when ice suddenly swelled at the poles, and sea level plummeted by hundreds of feet, the coastline receded to the edge of the continental shelf. Where there was once a vast shallow coastal province to feed and find love, there was now dry land, and—offshore—a precipitous plummet into the deep. There was no place for a small, coastal baleen whale to make a living.

“So you make life for these little guys a lot more difficult,” says Marx. “On the other hand, the big guys, they can be wide-ranging, and they’re capable of undertaking migrations from the poles and back to get the maximum amount of feeding and breeding opportunities.”

If the ice ages have been driving the past few million years of whale evolution then it’s been the brute, unthinking forces of geology guiding the course of life.

Though the ice ages began in earnest in only the past three million years, the plunge into the cold might have been set in motion long ago by the wander of the continents. Around 40 million years ago, the island continent of India—which had been barreling across the ocean since the Cretaceous—collided with Asia. When it did so, subduction zones that had been pulling the two continents together—and spewing CO2 out of volcanoes above—went quiet. Volcanic rock thrust up into the Himalayas and elsewhere was attacked by wind and rain, and weathered away, a process that drew down atmospheric CO2 even further. Today we find ourselves rightly concerned about soaring CO2 levels launching us back into the greenhouse of the whales’ early days, but falling CO2 over the past 40 million years seems to have dragged the planet into our modern ice age in the first place. Antarctica suddenly gained an ice sheet and the long, faltering descent into the modern ice ages had begun.

If this story is right, it might not have been the only time that the peculiar influence of plate tectonics has guided whale evolution. More than 30 million years ago, when South America divorced Antarctica and the sea spilled over between the two continents, the profound changes to ocean circulation supercharged the ocean with nutrients and plankton, and might have prodded the split between baleen whales and toothed whales—which curiously occurs around the same time. Even further back, 50 million years ago the extremely warm climate of the Eocene might have helped ease the whales’ wolf-like ancestor into the tepid water in the first place (according to Michigan paleontologist Philip Gingerich). And, before that, 56 million years ago, it might have been deep-sea volcanoes burning through fossil fuels under the North Atlantic seafloor that released enough methane and carbon dioxide to the atmosphere to set off an extreme spike in global temperatures—a heatwave that spawned a new group of animals that today includes deer, camels and giraffes, but that also included the ancestor of all whales. Understanding biology without geology is impossible, and vice versa.

Today human society is a geological force in its own right, and it’s an open question what its ultimate influence will be on the long evolutionary story of whales. The ocean is warming faster than it did even 56 million years ago, while ice sheets are poised for a collapse on time scales only seen at the end of the ice ages.  But even before this global chemistry experiment gets completely out of hand, whales have already—rather acutely—felt the influence of human civilization. Not that long ago, humans drew their oil, not from petroleum-soaked rocks, but from whales’ heads—and Nantucket played the role of Abu Dhabi in this cetacean oil economy. Whale extinction was on Melville’s mind as he watched this global slaughter unfold, firsthand. He wondered whether “Leviathan can long endure so wide a chase, and so remorseless a havoc.”

Though the hunt has relented, and Leviathan’s numbers have recovered somewhat, genetic studies indicate that populations of North Atlantic humpbacks were once 20 times more abundant than present. And given that climate and oceanography have played such an important role in whales’ evolutionary past, through ice ages and super-greenhouses both, what will their future hold in an ocean that’s not only rapidly warming but quickly acidifying as well?

Perhaps, counterintuitively, in the far future and in a far warmer ocean, whales might once again take on their dizzying diversity of forms of 10 million years ago, before the cull of the ice ages—when being a baleen whale didn’t mean having to migrate to survive. But, perhaps not.

“Even if, in theory, a warmer ocean could maybe support a higher diversity of whales, there’s no guarantee whales would ever get there at the current rate of change, Marx says. “On top of that, of course, you’ve got other factors, like: habitat degradation, fishing, noise pollution and goodness-knows-what, that all play their role as well. We’re sort of assuming ideal conditions and even then it’s speculative. But, if you just ask based on the climate data, there’s nothing for me to say that, you know, in a warmer ocean whales wouldn’t be more diverse.”

In a fossil-hunting trip to the South I took with Alabama state paleontologist Dana Ehret, ancient whales were on our minds, strewn, as they were, across the Alabama farmland—fossils that Melville claimed, “slaves in the vicinity took … for the bones of one of the fallen angels.” But Ehret specializes in the boom-and-bust evolution of another creature—the 60-foot, death-mawed megalodon shark. It’s an animal whose fate was inevitably tangled with that of whales. Curiously, as the earth descended into the icehouse around 3 million years ago, this other goliath of the ocean, mysteriously disappeared as well, along with all the smaller baleen whales.  Ehret doubts that it was the cold of the ensuing ice ages that killed “meg,” as has been sometimes proposed. Megalodon, after all, was a monster whose preposterous size alone likely generated enough heat to keep it warm. Rather, Ehret thinks, it was a knock-on effect of the mega-shark’s dwindling menu of whales to dine on.

“So what I think what happened was that ‘meg’ just got so big because it was literally just a buffet of all of these medium-sized whales,” he said. “And then all of a sudden the buffet closes and you’re left with this giant shark that can’t really support itself.

The closing of the baleen buffet might have killed off more than the megalodon. In 2010 in the Peruvian desert, a new whale was discovered, one that  shared the ocean with megalodon, though its teeth, at more than a foot long, dwarfed those of the destroyer shark. The terrifying whale earned a Linnaean name apposite to its grandeur: Livyatan Melvillei—literally, “Melville’s Leviathan.” That it swam in the same oceans with the 60-foot apex predator shark makes one grateful to swim in our considerably gentler seas. And like megalodon, Melville’s Leviathan might have fed on smaller whales as well, for it too seems to have failed to survive the transition to the modern, cooler world.

Like any subject in geology, pull on one thread—in this case, humpback whale barnacles—and all of Earth’s history begins to unspool. To understand an animal you have to understand its history, and to understand its history you have to first understand the history of the earth—and beyond. Indeed, whales even benefited from the influence of outer space as well, as the asteroid that executed T. Rex also cleared the ocean of its sea monsters, inviting that dog-like ancestor of all whales to colonize the seas ages ago.

Melville himself struggled with this intellectual vertigo that whales so reliably inspire: “In the mere act of penning my thoughts of this Leviathan, they weary me, and make me faint with their outreaching comprehensiveness of sweep, as if to include the whole circle of the sciences, and all the generations of whales, and men, and mastodons, past, present, and to come, with all the revolving panoramas of empire on earth, and throughout the whole universe,” he wrote, “not excluding its suburbs.”