Every animal with a brain needs sleep — and even a few without a brain do, too. Humans sleep, birds sleep, whales sleep and even jellyfish sleep.

Sleep is universal “even though it’s actually very risky,” said Paul-Antoine Libourel, a researcher at the Neuroscience Research Center of Lyon in France.

When animals nod off, they’re most vulnerable to sneaky predators. But despite the risks, the need for sleep is so strong that no creature can skip it altogether, even when it’s highly inconvenient.

Animals that navigate extreme conditions and environments have evolved to sleep in extreme ways — for example, stealing seconds at a time during around-the-clock parenting, getting winks on the wing during long migrations and even dozing while swimming.

For a long time, scientists could only make educated guesses about when wild animals were sleeping, observing when they lay still and closed their eyes. But in recent years, tiny trackers and helmets that measure brain waves — miniaturized versions of equipment in human sleep labs — have allowed researchers to glimpse for the first time the varied and sometimes spectacular ways that wild animals snooze.

“We’re finding that sleep is really flexible in response to ecological demands,” said Niels Rattenborg, an animal sleep research specialist at the Max Planck Institute for Biological Intelligence in Germany.

Call it the emerging science of “extreme sleep.”

Take chinstrap penguins in Antarctica that Libourel studies.

These penguins mate for life and share parenting duties — with one bird babysitting the egg or tiny gray fluffy chick to keep it warm and safe while the other swims off to fish for a family meal. Then they switch roles — keeping up this nonstop labor for weeks.

Penguin parents face a common challenge: getting enough sleep while keeping a close eye on their newborns.

They survive by taking thousands of catnaps a day — each averaging just 4 seconds long.Poets, sailors and birdwatchers have long wondered whether birds that fly for months at a time actually get any winks on the wing.

In some cases, the answer is yes — as scientists discovered when they attached devices that measure brain-wave activity to the heads of large seabirds nesting in the Galápagos Islands called great frigatebirds.

While flying, frigatebirds can sleep with one half of the brain at a time. The other half remains semialert so that one eye is still watching for obstacles in the flight path.

This allows the birds to soar for weeks at a time, without touching land or water.

On land, life is easy for a 5,000-pound northern elephant seal. But at sea, sleep is dangerous — sharks and killer whales that prey on seals are lurking.

These seals go on extended foraging trips, for up to eight months, repeatedly diving to depths of several hundred feet to catch fish, squid, rays and other sea snacks.

Each deep dive may last around 30 minutes. And for around a third of that time, the seals may be asleep, as research led by Jessica Kendall-Bar of Scripps Institution of Oceanography revealed.

Kendall-Bar’s team devised a neoprene headcap similar to a swimming cap with equipment to detect motion and seal brain activity during dives, and retrieved the caps with logged data when seals returned to beaches in Northern California.

The 13 female seals studied tended to sleep during the deepest portions of their dives, when they were below the depths that predators usually patrol.