Like people, spiders move by contracting muscles attached to a skeleton. But instead of an internal skeleton covered in flesh, spiders have an exoskeleton -- a stiff support structure on the outside of the body. Exoskeleton segments are connected together with joints so the spider can move them back and forth.
Muscles attached on the inside of the exoskeleton contract to move the legs inward, but spiders don't have any muscles to extend the legs back out again. Instead, they have to force bodily fluids (mainly blood) into the legs to push them outward. If a spider loses too much body water, it can't generate the necessary hydraulic pressure to push its legs out. This is why you sometimes see spiders on their backs with their legs curled up.
The exoskeleton is made of several layers of cuticle, a composite material containing various proteins and chitin, a long-chain polysaccharide (sugar). The chitin and protein molecules are arranged in long chains, in successive layers, like the grain in plywood.
This structure makes cuticle extremely strong, as well as highly effective at keeping the spider from drying out, but the material does have one serious drawback. While it's flexible enough for movement, it can't expand like human bones and tissue -- in other words, it can't grow. In order to increase its size, the spider has to form a new, larger cuticle exoskeleton and shed its old one (this is called molting).
Molting occurs frequently when a spider is young, and some spiders may continue to molt throughout their life. At the appropriate time, hormones tell the spider's body to absorb some of the lower cuticle layer in the exoskeleton and begin secreting cuticle material to form the new exoskeleton. The new exoskeleton is typically folded to some extent, so it can expand once the spider sheds the older one. The spider also secretes a molting fluid between the old exoskeleton and the new one. Once the new exoskeleton is finished, the spider absorbs the molting fluid. This creates a gap between the two exoskeletons, which makes it easier to separate them.
To shed the old exoskeleton, the spider has to bust out from the inside. It increases its heart rate to pump a lot of hemolymph (the spider's blood) from the abdomen into the cephalothorax. The pressure expands the cephalothorax, which pushes on the old exoskeleton until it cracks. The spider flexes its muscles until the old exoskeleton falls away.
Typically, the spider does most of its growing immediately after losing the old exoskeleton, while the new exoskeleton is highly flexible. The new exoskeleton is also very soft in this stage, making the spider particularly vulnerable to attack. Many species will lower themselves on a silk line during the molting process, so they're out of reach of predators while the cuticle material hardens.