How many principal bundles are there over a given base? I'm currently considering principal bundles and classifying spaces in the context of gauge theory and a crucial question came to my mind: 
Is there a way to say how many (isomorphism classes of) principal bundles there are over a given base space? 
For finite gauge groups the answer is yes: They correspond to elements of $\mathrm{Hom}(\pi_1(M),G)/G$ (where $M$ is the base and $G$ the gauge group). 
Is there a similar characterization for arbitrary compact Lie groups $G$?
 A: Let me add a few further remarks to the above very good answer. I think that the problem of classifying principal bundles is one of the most fundamental questions and applications of algebraic topology. 
The basic reason why the classification of principal bundles for $G$ a compact Lie group is so much more complicated than for a finite group is that the compact Lie group is not discrete and has higher homotopy. For example, the principal $G$-bundles over $S^n$ are classified by $\pi_n(BG)\cong \pi_{n-1}(G)$. In particular, the complete classification of bundles is not even known over spheres of arbitrary dimension. 
The question simplifies a bit if you stabilize, i.e., you look at $O(\infty)$-bundles or $U(\infty)$-bundles. In these cases, the homotopy sets $[M,BO]$ or $[M,BU]$ are topological K-groups and can in principle be computed using long exact sequences and such things. 
However, in general, the classification of principal bundles over finite CW-complexes is going to be more and more complicated with growing dimension. To give you some flavour of the sort of results to expect, you might want to have a look at some of the following papers:
A.Dold and H.Whitney. Classification of oriented sphere bundles over a $4$-complex. Ann. of Math. (2) 69 (1959), 667-677.
I.M.James and E.Thomas. An approach to the enumeration problem for non-stable vector bundles. J. Math. Mech. 14 (1965), 485-506. 
F.P.Peterson. Some remarks on Chern classes. Ann. of Math. (2) 69 (1959), 414-420. 
L. Smith. Complex 2-plane bundles over $\mathbb{CP}(n)$. Manuscripta Math. 24 (1978), 221-228. 
R.M.Switzer. Complex 2-plane bundles over complex projective space. Math. Z. 168 (1979), 275-287. 
... and for something more recent (look at the progress in dimension)...
M. Cadek and J. Vanzura. On oriented vector bundles over CW-complexes of dimension 6 and 7. Comment. Math. Univ. Carolin. 33 (1992), 727-736. 
B. Antieau and B. Williams. On the classification of oriented 3-plane bundles over a 6-complex. arXiv:1209.2219. 
This does not even say anything about the classification of principal bundles with exceptional structure groups....
[Edit:] I should have said that in all the above cases, the results are proved using obstruction theory. The answer then classifies bundles in terms of characteristic classes in suitable cohomology theories, together with additional data like compatibilities with Steenrod operations etc. This is a standard procedure in algebraic topology. Look at Hatcher's algebraic topology book for an introduction to Postnikov towers and obstruction theory.
A: If $G$ is a connected compact Lie group and the base $M$ is homotopy equivalent to a finite cell complex, then a rough count of the set $[M, BG]$ is given by  the rational homotopy theory. The point is that the classifying space $BG$ is rationally homotopy equivalent to the product of Eilenberg-MacLane spaces, e.g. 


*

*for $G=U(n)$ each  Eilenberg-MacLane space corresponds to the Chern class.

*for $G=SO(n)$ each Eilenberg-Maclane space corresponds to Pontryagin or Euler class.
For example, it follows that up to finite ambiguity a principal $U(n)$-bundles over $M$ is determined by its rational Chern classes, and conversely a multiple of any element in $\oplus_{i=1}^n H^{2i}(M;\mathbb Z)$ is realized as the collection of Chern classes of a principle $U(n)$-bundle over $M$.
One standard example (going back to Serre) is that there are only finitely many principal $G$-bundles over an odd-dimensional sphere (because it has no even-dimensional rational cohomology).
Another example is when $G=U(1)$. Then $[M, BU(1)]=[M, K(2, \mathbb Z)]$ which is bijective to $H^2(M;\mathbb Z)$ via the Euler class (here $M$ is any paracompact space, see Husemoller's book "Fiber bundles", section on characteristic classes).
This is standard material but unfortunately not written in textbooks (except for the $U(1)$ case) so I refer to appendices in my papers   here and here.
ADDED: regarding the difference between $SO(3)$ and $SU(2)$ bundles, a correct thing to say is that $SU(2)$ equals $Spin(3)$, so an $SO(3)$ bundle has a Spin structure which happens exactly when its second Stiefel-Whitney class vanishes. The class lives in $H^2(M;\mathbb Z_2)$. Thus the question is what "proportion" of $SO(3)$ bundles have a Spin structure. (I put proportion in quotation marks because
often both sets of bundles are countably infinite.) The answer of course depends on $M$. If $H^2(M;\mathbb Z_2)=0$, every $SO(3)$ bundle over $M$ is spin. In general, the universal coefficients theorem tells us which classes in $H^2(M;\mathbb Z_2)$ come from $H^2(M;\mathbb Z)$, and any class in the latter group can be realized as the Euler class of an $SO(2)$ bundle, and its mod 2 reduction is the Stiefel-Whitney class. Since any $SO(2)$ bundle is gives rise to an $SO(3)$ bundle we can realize many nonzero classes in $H^2(M;\mathbb Z_2)$ as Stiefel-Whitney classes of some $SO(3)$ bundles; these bundles are not spin. 
