Rats, by their very nature, are social animals. In the wild they live in colonies where they live in small groups. They generally would never be found living alone, and we recommend this when keeping them as pets. It's ideal to keep at least two so that they have company, so that they have each other to rat around with, and so that they have the opportunity to exhibit the normal behaviors that a rat would exhibit when they're with another of their kind.
Certainly there's no limitation on the number of rats you could have, within reason of course, and that fit with the type of caging you have, the type of environment, and your own personal interest in keeping them. I strongly recommend having at least two at any time and not keeping a single rat alone. Certainly there may be instances where keeping a single rat is acceptable, but as a general rule having them in small groups, having them in family units.
What often works for a number of people is to set up what they call a harem, where they'll have one male that lives with a group of two or three females. Certainly in this instance that male is going to have been sterilized so he can't reproduce, but that generally tends to work out really well for them to live in groups.
In most cases there isn't a big difference in whether sexes will get along, although there is the possibility that two males may become territorial, may become argumentative, and actually fight. In these instances it's recommended to have them neutered so that they can get along really well together. And if you're introducing large numbers of rats, or you want to have a large community that live together, it's strongly recommended to make sure that the animals are spayed or neutered so that there is no accidental breeding.
Overall it's important for the rat's health and well being, and it's important for the times that no one is around that they're not just left alone. And it also allows them to groom each other, to play with each other, and to exhibit a lot of the normal behaviors that rats show with each other rather than having them sit by themselves alone during the times you're not there.
So, overall it's recommended to always have at least a pair of rats. Many people will go up to having several more depending on their environment. But it's really important both for their social well being, for their overall health, and for them to be able to exhibit natural behaviors that rats exhibit with each other.