I know I can have at least 2 classes, but can I have more? This is of course at the discretion of my GM whether he allows me to have 20 classes if I'd wish. But are there any set rules for this?
You can have one class per character level
There is no limitation as to how many different classes you can select when multiclassing. The character advancement rules just state:
A character advances in level as soon as he earns enough experience points to do so—typically, this occurs at the end of a game session, when your GM hands out that session's experience point awards.
Instead of gaining the abilities granted by the next level in your character's current class, he can instead gain the 1st-level abilities of a new class, adding all of those abilities to his existing ones. This is known as “multiclassing.”
Since there are more than 20 classes (even without considering prestige classes), you can have levels in 20 different classes at level 20. This is a highly silly thing to do though.
As many as the GM allows
- A creature can't take levels in both an alternate class and the class for which the alternate class is an alternate (e.g. a creature can't be a cavalier 1/samurai 1).
- Some special rules exist for multiclassing between hybrid classes and their parent classes, but there aren't any restrictions on multiclassing between them. (In the initial hybrid classes playtest such restrictions did exist, but these were removed for publication. Memories are long, though, and some still cite this restriction.)
- Multiclassing between unchained classes and core classes may be allowed, and I can't find anything prohibiting it, but given that Pathfinder Unchained is still fairly new, ask the GM. (Note that things with the same name general overlap instead of add, but whether this applies to an entire character class is still up in the air.)
- Variant multiclassing is a whole separate subsystem.
So, generally, there are very few restrictions on multiclassing in Pathfinder. Practically, a class usually becomes more powerful as it gets higher in level so taking, for example, the first level in 20 classes is less optimized than 20 levels in one class, but nothing prohibits strange combinations like a level 20 character taking the first level in 20 different classes.
It's possible for a character to be unable to take levels in certain classes because the character doesn't meet the class's requirements (for many classes this is usually because of a character's alignment while for prestige classes this is usually because of the prestige class's entry requirements), but, short of this, go nuts.
Free multiclassing is supported by the rules on Character Advancement on Advancing Your Character, which say
When adding new levels of an existing class or adding levels of a new class (see Multiclassing, below), make sure to take the following steps in order. First, select your new class level. You must be able to qualify for this level before any of the following adjustments are made. Second, apply any ability score increases due to gaining a level. Third, integrate all of the level's class abilities and then roll for additional hit points. Finally, add new skills and feats. For more information on when you gain new feats and ability score increases, see Table: Character Advancement and Level-Dependent Bonuses.
...and the rules on Multiclassing, which say
Instead of gaining the abilities granted by the next level in your character's current class, he can instead gain the 1st-level abilities of a new class, adding all of those abilities to his existing ones. This is known as "multiclassing."
...And there's no limit to that second part except, as per this answer, you do only get 1 class level per character level.
Some GMs will have house rules that limit free multiclassing for a variety of reasons (e.g. some GMs believe grabbing low-level abilities from a variety of classes more powerful than acquiring high-level abilities from a lone class and restrict multiclassing for balance; some GMs believe that a prestige class should be "completed" before another prestige class can be taken). Ask the GM before building your level 20 character with 20 different classes.
Finally, Pathfinder encourages staying with a single class through its use of capstone class features—high-level abilities available only to single-classed or barely-multiclassed characters—and through favored class benefits. A character who multiclasses excessively isn't punished but, instead, just rewarded less.
The guide "Dipping for Fun and Profit (Mostly Profit)" describes several strategies for multiclassing.