Ten categories, rarest wins
The rule
The ranking is not arbitrary. Every hand beats the hands that are easier to make than it.
High card, one pair, two pair, three of a kind, straight, flush, full house, four of a kind, straight flush. A royal flush is not a tenth category, it is the highest straight flush there is.
The order follows from how many ways each one can be made. There are more distinct straights in a deck than flushes, so a flush beats a straight. Learn it that way once and you never have to recall the list under pressure, because you can rebuild it.
Inside a category, the ranks decide. Two pair aces and threes beats two pair kings and queens, because the top pair is compared first. The same rule runs all the way down.