It can serve as antennae, extra limb, communicate mood, and is a counterbalancing tool for acrobatics.
Tail up is good mood, curious, happy. Tail down is concerned, frustrated, confused; swiping tail is either frustration or the cat preparing their balance to stalk or pounce. Sometimes (with a cat familiar to you) gently brushing the tail up into the happy position is like telling them "hey, cheer up". Cats can use their tail almost as a rear-view mirror to swipe the space behind them checking for retreat options or another cat sneaking up on them - similar to how whiskers alert them whether they space they're intruding into is too narrow for them or not.
I noticed my female cat expresses affection with a tail-wrap around my leg. It's like she's hugging or putting a gentle arm around me like a buddy. Sometime's it's quick as she passes, almost like you'd touch the shoulder of a friend when moving behind their chair. She also really wants to be part of my yoga stretching - she'll fuss around on all sides of the mat, sometimes looking for a place to lie down alongside, sometimes mimicking my position, sometimes she'll pace like an instructor, whipping her tail around on all sides, tapping everywhere on my body like she's checking or correcting my positional form. It would seem a cat in the way would be annoying, but she totally understands if she's laying on the side I want to roll toward and feels me move she's up like a flash to find another comfortable spot to sprawl.
I had another cat years ago that almost seemed to be able to sense tension and would indicate this. Once when lying on the ground she carefully walked up and balanced on me with front paws and back paws on each of my hip sockets and started kneading and shifting the weight of her back feet literally massaging my hip sockets as if she were concerned for my flexibility.