Hairballs are one of those nasty things that cats are famous for.
Why do cats get hairballs?
You cat has little barbs, or hooks, on their tongue that are designed to clean and catch their fur. These barbs pull out the dead hair from their coat, which they then swallow. Most of the the swallowed hair passes through their entire digestive system, and thus goes unnoticed by you. However, not all of it makes it out of their stomach. When enough of it has gathered in their stomach, it forms a ball and will get thrown up.
The more your cat sheds, the more likely they are to have hairballs. Long hair breeds will likely have more hairballs than short haired breeds. You may be remembering, fondly, when you cat was a kitten and never seemed to have hairballs. Good observation! You are right. Kittens are not very good at grooming, so they are less likely to have hairballs. As your cat gets older, their grooming techniques improve. So when they groom they are pulling out, and swallowing, more of the dead hair. This is why adult cats get hairballs and kittens do not.
If your cat is prone to hairballs, there are things you can do to help.
You can give them hairball medicine. This is a paste, that they usually like to eat, that helps them pass the hairball by lubing up their system.
You can give them hairball food. This is specially designed food to assist hairballs to pass through their digestive tract, usually high in fiber.
You can give them a plant to eat. Yes this makes them throw up more, or so it seems. The reality is the plant provides a natural fiber that helps them to pass, or throw up, the hairball.
If you cat has persistent vomiting, ongoing hacking, retching and gagging without producing a hairball, lethargy, constipation, or diarrhea, you should call your vet.
Though a hairball is a natural part of your cat, they can still cause intestinal blockages. If this happens your cat will need professional treatment.