If you ask people what animal eyes are used for, they'll say: same thing as human eyes. But that's not true at all.

In his lab at Lund University in Sweden, Dan-Eric Nilsson is contemplating the eyes of a box jellyfish. Nilsson's eyes, of which he has two, are ice blue and forward facing. In contrast, the box jelly boasts 24 eyes, which are dark brown and grouped into four clusters, called rhopalia. Nilsson shows me a model of one in his office: It looks like a golf ball that has sprouted tumors. A flexible stalk anchors it to the jellyfish. "When I first saw them, I didn't believe my own eyes," says Nilsson. "They just look weird."

Four of the six eyes in each rhopalium are simple light-detecting slits and pits. But the other two are surprisingly sophisticated; like Nilsson's eyes, they have light-focusing lenses and can see low-resolution images.

Nilsson uses his eyes to, among other things, gather information about the diversity of animal vision. But what about the box jelly? It is one of the simplest animals, just a gelatinous, pulsating blob with trailing bundles of stinging tentacles. It doesn't even have a proper brain — merely a ring of neurons running around its bell. What information could it possibly need?

In 2007, Nilsson and his team demonstrated that the box jelly Tripedalia cystophora uses its lower lensed eyes to spot approaching obstacles, like the mangrove roots that it swims among. It took them another four years to discover what the upper lensed eyes do. The first big clue was a free-floating weight at the bottom of the rhopalium that ensures that the upper eye is always looking upward, even if the jellyfish swims upside down. If this eye detects dark patches, the jellyfish senses that it's swimming beneath the mangrove canopy, where it can find the small crustaceans that it eats. If it sees only bright light, it has strayed into open water, and risks starving. With the help of its eyes, this brainless blob can find food, avoid obstacles, and survive.

The box jellyfish's eyes are part of an almost endless variation of eyes in the animal kingdom. Some see only in black and white; others perceive the full spectrum of the rainbow and beyond, receiving forms of light invisible to our eyes. Some can't even gauge the direction of incoming light; others can spot running prey miles away. The smallest animal eyes, adorning the heads of fairy wasps, are barely bigger than an amoeba; the biggest are the size of dinner plates, and belong to gigantic squid species. The squid's eye, like ours, works as a camera does, with a single lens focusing light onto a single retina, full of photoreceptors — cells that absorb photons and convert their energy into an electrical signal. By contrast, a fly's compound eye divides incoming light among thousands of separate units, each with its own lens and photoreceptors. Human, fly, and squid eyes are mounted in pairs on their owners' heads. But scallops have rows of eyes along their mantles, sea stars have eyes on the tips of their arms, and the purple sea urchin's entire body acts as one big eye. There are eyes with bifocal lenses, eyes with mirrors, and eyes that look up, down, and sideways all at the same time.

At one level, such diversity is puzzling. All eyes detect light, and light behaves in a predictable manner. But it has a multitude of uses. Light reveals the time of day, the depth of water, the presence of shade. It bounces off enemies, mates, and shelter. The box jellyfish uses it to find safe pastures. You use it to survey landscapes, interpret facial expressions, and read these words. The variety of tasks that eyes perform is limited only by the fecundity of nature. To understand how eyes evolved, scientists need to do more than examine their structures. They need to do what Nilsson did with the box jellyfish: understand how animals use their eyes.

Living animals illustrate every possible intermediate between the primitive light-sensitive patches on an earthworm and the supersharp camera eyes of eagles. Nilsson has even shown that the former can evolve into the latter in a surprisingly short amount of time.

He created a simulation that starts with a small, flat patch of pigmented light-sensitive cells. With each yearlong generation, it becomes a little thicker. It slowly curves from a sheet into a cup. It gains a crude lens, which gradually improves. Even under the most adverse conditions, with the eye improving by just 0.005 percent each generation, it takes just 364,000 years for the simple sheet to become a fully functioning camera-like organ. As far as evolution goes, that's a blink of an eye.

But simple eyes should not be seen as just stepping-stones along a path toward greater complexity. Those that exist today are tailored to the needs of their users. A sea star's eyes can't see color, fine detail, or fast-moving objects. Then again, a sea star isn't trying to spot and snag a running rabbit. It merely needs to spot coral reefs — huge, immobile chunks of landscape — so it can slowly amble home. Its eyes can do that; it has no need to evolve anything better.

"Eyes didn't evolve from poor to perfect," Nilsson says. "They evolved from performing a few simple tasks perfectly to performing many complex tasks excellently."

A few years ago he enshrined this concept in a model that charts eye evolution in four stages, each defined not by physical structures but by the things it allows animals to do. At the first stage, the animal can monitor the intensity of ambient light, to gauge the time of day or its depth in water. You don't need a true eye for this; an isolated photoreceptor will do. The hydra, a small relative of the jellyfish, has no eyes, but it does have photoreceptors. These receptors control the hydra's stinging cells, so that they fire more easily in darkness.

Animals at the second stage of Nilsson's model can tell where light is coming from, thanks to a shield that blocks light from certain directions. A receptor like this gives its owner a one-pixel sense of the world — enough to help the animal move toward a source of light or swim away from it. That's exactly what many marine larvae have.

At stage three, the shielded photoreceptors cluster into groups. Now the creature can integrate information about light from different directions, producing an image of its world, blurry and grainy though it may be. This is when light detection becomes vision proper. Animals with stage-three eyes can find suitable homes, as sea stars do, or avoid obstacles, as box jellyfish do.

Stage four is where the evolution of eyes — and their owners — really takes off. With the addition of lenses for focusing light, vision becomes sharp and detailed. "When you get to stage four, the list of tasks has no end," says Nilsson. This flexibility might have been one of the sparks that ignited the Cambrian explosion, an outburst of speciation around 540 million years ago, when the ancestors of most modern animal groups appeared. Suddenly the encounters between predators and prey, previously limited to sniffing, tasting, and feeling at close quarters, could play out over distance. An arms race began, and animals responded by ballooning in size, becoming more mobile, and evolving defensive armor.

As they evolved, so did their eyes. All the basic visual structures that exist today were present during the Cambrian, but they have been elaborated in an extraordinary variety of ways — again for specialized tasks. The male mayfly has what looks like a huge compound eye glued on top of another smaller one, devoted to scanning the skies for silhouettes of flying females. The aptly named four-eyed fish has two camera eyes, each divided in two, so one half can sit above the water's surface and examine the sky while the other looks out for threats and prey below. The human eye is reasonably fast, adept at detecting contrast, and surpassed in resolution only by the eyes of birds of prey — a good all-around eye for the most versatile animal of all.

Sometimes evolution does U-turns. Eyes are as complex as their owners need them to be, and if those needs diminish, so do the eyes. Most birds and reptiles see color with four types of cone photoreceptors. But mammals evolved from a nocturnal ancestor that had lost two of these cones, presumably because color vision is less important at night and because cones are most effective in bright daylight.

If the benefits of seeing dwindle to none, some animals lose their eyes altogether. The Mexican tetra is an excellent example of this. In the Pleistocene epoch, some of these small freshwater fish swam into several deep caves. Their eyes were of little use in the pitch-blackness, so their descendants evolved into different populations of blind cave fish. These degenerations occurred because eyes take a lot of energy to make and maintain.

This explains why animals don't have eyes that are better than they need. Squandering energy on a useless sensory system is a recipe for extinction. Eyes may be assembled from old parts, plagued by ancient bugs, and prone to breaking — but they're also exquisitely tuned to the needs of their owners. They are testament to both evolution's endless creativity and its merciless thrift.

At the University of Maryland, Baltimore County, Tom Cronin peers into an aquarium tank, and two googly compound eyes, like muffins mounted on stalks, peer back. "Mr. Googles," as Cronin affectionately calls him, is a mantis shrimp — one of a group of crustaceans named for the quick-punching arms protruding beneath their heads, like those of the praying mantis. Mr. Googles' arms end in formidable hammers, which unfurl with such speed and force that they can shatter seashells, and aquarium glass.

Each of the mantis shrimp's eyes has three separate regions that focus on the same narrow strip of space, providing depth perception without help from the other eye. The shrimp's eyes can also see ultraviolet parts of the spectrum that are invisible to us. And while we have three kinds of color receptors in our retinas, Cronin discovered that mantis shrimps have 12, each tuned to a different color. "It didn't make sense. None of it did," he recalls.

For years, scientists assumed that with all those receptors the mantis shrimp must be the undisputed champion of color discrimination. But Hanne Thoen, at the University of Queensland, Australia, smashed that idea in 2013. She presented mantis shrimps with optic fibers displaying different colors, and rewarded them with food if they attacked one in particular. They performed appallingly: They couldn't even distinguish colors whose differences are patently obvious to us.

So why all the receptors? Thoen suspects that they have everything to do with pugilistic prowess. We do a lot of visual processing in our retinas, adding and subtracting information from our cones before sending it to our brains. Perhaps the mantis shrimp instead passes the responses of all 12 of its color receptors directly up to its brain, so it can make quick decisions about its superlatively fast strikes.

But Cronin is unconvinced. Back in his lab, he dangles a pipette in a petri dish containing a smaller mantis shrimp. It tracks the intruding object with its eyes, then lashes out. The blow is powerful enough to make an audible crack, like a finger snapping. "That little guy spent a long time thinking before he whacked it. It's not a decision they make like that," says Cronin, snapping his own fingers. "So what's it all for?"

It's the question that Dan-Eric Nilsson always asks as well. It's not enough to know the structure of the mantis shrimp's eyes or the neural signals that they send to the brain. Ultimately, to understand why they are the way they are, we need to know how they are used. To communicate with each other? To catch prey quickly? To better see the riot of colors in coral reefs? This is the ultimate truth of animal eyes: We can only understand their evolution when we learn to see the world through them.

Excerpted from an article that originally appeared in the February 2016 issue of National Geographic. Reprinted with permission.