Cats rub against each other to mark their territory. When a cat is in a place it feels safe to be in, it will spread its scent around, and the way it does this is by rubbing against each other.
When cats smell familiar scents in their territory, they feel safe and comfortable. Cats have a strong sense of territory; leaving their scent on their territory not only asserts ownership but also alerts and warns intruders.
Moreover, when a cat rubs against you, it's expressing its affection. When your cat rubs against you, you can gently stroke its head to show it that you like it too. 
1. Mark the territory
Cats rub their heads against objects to mark their territory. They leave their scent on these objects, both to declare their territory and to warn other animals.
2. I like your behaviorIf a cat rubs its head against you seeking petting, it's a very friendly social behavior. The chin and head are where a cat's scent glands are concentrated, and it wants to leave its own unique scent on you; this is also a way for the cat to feel happy.