(CNN)Sharks are some of the ocean's top predators. In fact, sharks and their relatives were the first vertebrate predators on Earth.
Shark fossils date back more than 400 million years -- that means sharks managed to outlive the dinosaurs, survive mass extinctions, and continue to serve an important role near the top of underwater food chains.
After millions of years of adaptations, more than 500 species of sharks swim the planet's oceans today, and sharks are found in almost every type of ocean habitat. So how have sharks evolved to suit their environments?
From ancient ancestors to modern sharks
To understand how modern sharks adapted and evolved, we first have to look back through the fossil record of their ancestors.
Originating from a time before dinosaurs walked the earth, the earliest shark scales date back about 425 million years, and the earliest shark teeth are from the Devonian Period, about 410 million years ago. And some fossils of shark-like chondrichthyans scales (from a group of fish including sharks, rays, and their relatives) date as far back as 440 million years.
Because shark skeletons are made of soft cartilage, which doesn't fossilize well, most of what scientists know about ancient sharks comes from teeth, scales and fin spine fossils. But the cartilage of early sharks would also be similar to shark cartilage today, which distinguishes sharks from most fish that have heavier skeletons made of bone. Having a skeleton made of lightweight cartilage allows sharks to conserve energy and swim long distances.
"From some of the soft tissue we have found fossilized, early sharks would have had a similar body plan to most modern day sharks," said Emma Bernard, fish fossil curator at the British Natural History Museum.
That means sharks' bodies were tapered at both ends and the fins were in similar places, optimized to make them high-speed predators. But the size of sharks varies greatly. Present-day sharks can range from about 1 to 55 feet. And according to Bernard, sharks about 60 feet long (18 meters) exist in the fossil record.
"The common thread is that they exploit different parts of the marine ecosystem," Bernard explained. "So the more generalist an animal is the more likely it will be to adapt and survive changes in its environment, and the group as a whole will survive."
Wide variety of sharks and adaptations
Teeth are one good illustration of how modern day sharks evolved in different ways. Many early sharks had conical, non-serrated teeth. Meanwhile, many sharks today evolved to have triangular teeth that were flat and serrated like a steak knife, which helps them bite off chunks of prey.
But not all shark teeth are the same. Some bottom-dwelling sharks that feed on mollusks have teeth suited to grinding and cracking shells open. Others, such as goblin sharks (which have a crazy jaw protrusion), have needle-like teeth used for piercing fish. And the biggest fish in the ocean, the filter-feeding whale shark, eats plankton and doesn't actually use its 300 rows of pointed teeth to eat.
"The most interesting adaptation for me, as someone who studies shark feeding, is probably their flexibility in diet," said shark evolution researcher Lisa Whitenack in an email. "If one prey type decreases in abundance, then they could potentially switch to something else."
Sharks also have a wide variety of migration patterns. Marine conservation biologist David Shiffman said. He once saw a nurse shark stay under the same rock for a week.
"But some shark migrations are thousands of miles," Shiffman said. "It's amazing how far they can swim and for how long."
Some species travel long distances on a daily basis, yo-yo-ing from shallow to deep water to hunt. For example, the blue shark will dive more than a thousand feet during the day but return to the surface to spend the night.
In general, sharks and their adaptations are difficult to generalize.
"They are in deep water and shallow water, cold and warm water, even occasionally freshwater," said Whitenack, an Associate Professor of Biology and Geology at Allegheny College. "When you look at 'sharks' as a group, it's no wonder that they've survived mass extinctions -- chances are some small pocket of species will survive somewhere."
Need for speed
One way to survive in an ocean full of other predators is to be fast. So many sharks are built for speed.
Shark skin is made up of tiny V-shaped scales called dermal denticles, because they resemble teeth more than fish scales. These skin denticles decrease drag in the water and help sharks glide more quietly.
Many sharks' tails, called caudal fins, are larger on top than on the bottom, which allows the animals to swim more efficiently.
Some sharks also have a mechanism on their caudal fins called a horizontal keel, which reduces turbulence and allows them to swim faster.
One of the fastest fish in the ocean is actually a shark -- the shortfin mako -- which can reach a top speed of about 55mph. Unlike other sharks that swim in a wavy pattern, mako sharks swim in a straighter pattern. These speedy sharks also have a face shaped like a cone to glide through the water more efficiently.
A sixth sense
Sharks also have an extra sense -- the ability to sense electromagnetic fields. That means they can detect the Earth's magnetic field as well as the small electric fields that marine animals create when moving their muscles.
"They use that for navigation, to swim in the open ocean, and also to find prey that's buried under the sand," Shiffman said. "That's why hammerheads have that shape. It's like sweeping a metal detector across the sand."