Why groups of individuals sometimes exhibit collective 'wisdom' and other times maladaptive 'herding' is an enduring conundrum. Here we show that this apparent conflict is regulated by the social learning strategies deployed. We examined the patterns of human social learning through an interactive online experiment with 699 participants, varying both task uncertainty and group size, then used hierarchical Bayesian model fitting to identify the individual learning strategies exhibited by participants. Challenging tasks elicit greater conformity among individuals, with rates of copying increasing with group size, leading to high probabilities of herding among large groups confronted with uncertainty. Conversely, the reduced social learning of small groups, and the greater probability that social information would be accurate for less-challenging tasks, generated 'wisdom of the crowd' effects in other circumstances. Our model-based approach provides evidence that the likelihood of collective intelligence versus herding can be predicted, resolving a long-standing puzzle in the literature.