This is absolutely amazing:
The process (called molting) is a complicated, multi-day process, according to NOAA:
Crabs (and other crustaceans) cannot grow in a linear fashion like most animals. Because they have a hard outer shell (the exoskeleton) that does not grow, they must shed their shells, a process called molting. Just as we outgrow our clothing, crabs outgrow their shells. Prior to molting, a crab reabsorbs some of the calcium carbonate from the old exoskeleton, then secretes enzymes to separate the old shell from the underlying skin (or epidermis). Then, the epidermis secretes a new, soft, paper-like shell beneath the old one. This process can take several weeks.
A day before molting, the crab starts to absorb seawater, and begins to swell up like a balloon. This helps to expand the old shell and causes it to come apart at a special seam that runs around the body. The carapace then opens up like a lid. The crab extracts itself from its old shell by pushing and compressing all of its appendages repeatedly. First it backs out, then pulls out its hind legs, then its front legs, and finally comes completely out of the old shell. This process takes about 15 minutes.
Female, for example, Red King Crab preparing to molt Over the next few weeks, the crab gradually retracts all of its body parts from the outer shell by a few millimeters, while it begins to secrete a new shell beneath the old one. If we pull off one of the small mouthparts from the crab, and place it under a microscope, you can see the new shell beginning to retract from the old one. When a crab molts, it removes all its legs, its eyestalks, its antennae, all its mouthparts, and its gills. It leaves behind the old shell, the esophagus, its entire stomach lining, and even the last half inch of its intestine. Quite often, many crabs in a population molt at the same time of year, and their old shells wash up on the beach. If you find something on the beach that looks like a dead crab, pick it up, open the lid, and look closely inside.