Circuit breaker capacity
How many circuit breakers can be installed in a main panel box?
If the main is 100 amp? If the main is 150 amp? If the main is 200 amp? 
this is a good question
for me to ask the code department as well. as I need to add a few breakers to the alreay quite crowd panel box. Don't know if they have a limit on the code for that although I still see a few empty slot on the panel...

As many as the panel is listed for, of course! In a typical situation, the panel will have two numbers... one for the number of breakers, another for the number of circuits. The difference between the two numbers comes about because of 'tandem' breakers (2 circuits in 1 breaker space) as well as '2pole' breakers (which, when wired as 240V, would be 1 circuit in 2 breaker spaces).
As a general rule of thumb, in a residential situation in the US, you'll see panels max out at 40 circuits. None of this is based on amperage of the panel. In my house I have a 1/1 (1 breaker, 1 circuit) 200A panel and a 40/40 (40 breakers, 40 circuits) 200A panel. (ok, and an old 20/20 100A that I'm getting rid of) 
So the only limit is the spaces in the main box?
If the main panel has 20 spaces then 20 circuit breakers can be install? Can all these spaces have 20 amp breakers? Or is there a limit to the total amps that all breakers draw? If the main panel has 40 spaces then 40 circuit breakers can be installed? 
Generally speaking, yes, however many spaces there are, can be filled with breakers  of the single pole variety. You can't, however, just cram a 40 space breaker with tandems (giving you a total of 80 circuits).
The rating of the panel is distinct from the number of spaces. You'll need to limit yourself to both. So, lets say you have a 30/40 150A panel. This means you have 30 spaces, and can have a total of 40 circuits (generally speaking this means that 10 of the spaces will allow a tandem breaker to be installed  but you are responsible for what you put it, no matter what you could physically install)... and the total draw for all circuits can't exceed 150A. This means you could put in a 100A breaker (this would almost certainly be a 2pole, taking up 2 spaces) to feed to a subpanel if you like (as long as your feeder conductors to that panel are large enough). There IS a difference between the amount of amperage drawn and the size of each breaker. This means, for example, that you can have 15 breakers, of size 20A, in a 200A panel  as long as you don't have more than 200A of actual load. You are also supposed to balance the load on the two phases  however that's generally difficult to do in a residential situation. Some math... Lets say you take 7 halogen floor lamps in one room (yes, this is a very bright room), rated at 300W each, and plug them all into a single circuit, protected by a 20A breaker... 2100W/120V = 17.5A. Now lets say you have 10 rooms like this... 17.5A x10 rooms = 175A  this would be problem in a 150A panel, even if it had 30 spaces and would allow for 40 circuits. 
Is there a formula for deteremining if you reached the max circuits for the main panel?

Yes: Look at the label on the panel. Count the number of circuits coming into the panel. Subtract.
If you are looking at installing a new panel, it will have the capacity (amperage, circuits and breakers) printed both on the shipping box and in the panel itself, and maybe in the paper documentation as well. If you are looking at an existing panel, then you can likely only go by the panel label. If there is no label, or it is illegable, you can try to go to the manufacturer, but that could be difficult unless you have the exact part # of the panel (if you don't have the circuit capacity, you probably don't have the exact part #... catch 22). If it was me (and now we get into opinion territory...), in absense of all other info, I would go by the number of circuit breaker spaces and assume that it could take the number of circuits as would be present if I filled all spaces with single pole breakers. To be absolutely picky technical, it would not surprise me at all that in the absense of any explicitly stated circuit capacity, you are not allowed by NEC to increase the circuit count at all, as you no longer have a manuf. listing/label/documentation to go by. 
All times are GMT 5. The time now is 06:06 PM. 