Some people enjoy the way it feels to sit on warm sand, while others dislike how the gritty particles always seem to find a way inside a swimsuit. Sand is great for building castles, but just a few grains can ruin a bite of even the best sandwich.

Whether you love it or hate it, if you go to the beach this summer, there’s no way to avoid sand. So, what is sand, and where does it come from?

“Sand is basically small rocks,” says Matt Kendall, a marine biologist with the National Oceanic and Atmospheric Administration.

While we tend to associate the material with beaches, most sand begins its “life” high in the mountains, says Kendall. As tree roots, wind and ice break larger rocks apart, those pieces sometimes wind up in streams and rivers. Once there, the constant flow of water churns the rocks up, as if they’ve been put in a blender that never turns off and can span thousands of miles. Eventually the itty bitty pieces of rock are washed all the way to the ocean, where waves break them further and push them back onto the shore.

There are other kinds of sand, too. Black sand comes from ground-up lava, for instance. And in the Caribbean, much of the sand you see comes from tiny creatures called foraminifera.

“They’re like little amoebas with a shell,” says Kendall. “And they make these beautiful structures that are sand-size particles. And when they die, the shells are left over, and they make this beautiful pink sand.”

But the best backstory for a sandy beach relates to the magical, white sand beaches of Hawaii, which you may have seen in movies and pictures. With turquoise water on one side and vibrant green palm trees on the other, the pristine shores look like they’re made of powdered diamonds and pearls. However, the beaches are actually made of parrotfish droppings.

Parrotfish eat coral. With super strong beaks, they crunch through the coral’s skeleton like it’s a candy apple in an attempt to get at the nutrients inside. More teeth in the parrotfish’s throat grind the coral up further, and by the time the bits pass through the digestive tract and out the other end, what was once hard, rocklike coral has been turned into a cloud of white dust. Waves wash the stuff onto shore, where tourists pay thousands of dollars to take selfies upon it, perhaps never realizing where the luxurious sand comes from.

“If you’re lying on your towel and you look around and see white sand, that’s parrotfish poop,” says Kendall with a laugh.