Why do we stretch?

And other animals (notably cats) besides.

I just had the overwhelming urge to roll on my bed and stretch seemingly every muscle of my body (which I did.)

I know this must be a reflex action, like taking a breath after breathing too shallowly, but what is the physiological background here?

I think its somehow tied to relieving muscle cramping. People stretch when they climb out of bed, exit a movie theater, finsih a long drive, etc.

I think animals sometimes stretch as part of their body language. I know for cats and dogs, it seems to be a fairly universal ‘hello I missed you!’