Cats swallow loose hair while grooming, and most passes through the gut. A hairball is simply hair that comes back up when it clumps in the stomach.
Brush regularly, especially long-haired breeds, to remove loose fur before it is swallowed. During shedding season, daily brushing helps most.
Hairball-control diets use added fiber to move hair through the digestive tract, and adequate water keeps things moving. Wet food supports hydration.
Occasional hairballs are fine, but weekly or frequent ones, along with vomiting, appetite loss, or constipation, warrant a vet visit to rule out blockages.
Never give laxatives or oils without veterinary guidance; some human remedies are unsafe for cats.