What’s the point if it?

I’ve grown up with it my entire life and see that everyone does it and I’m genuinely curious to know why it’s done? But why are carpets put it in the kitchen and bathroom? I always think those two places should be the most “clean” if that makes sense and I feel like carpets attract and keep bacteria? Idk just curious to know why? To know if I should do it once I have my own place. I understand a bath bat so you don’t drench your floor or slip, but not like additional carpets. Idk just curious?