In this paper we analyze the role played by self-confidence, modeled as beliefs about one's ability, in shaping task choices. We propose a model in which fully rational agents exploit all the available information to update their beliefs using Bayes' rule, eventually learning their true type. We show that when the learning process does not convergence quickly to the true ability level, even small differences in initial confidence can result in diverging patterns of human capital accumulation between otherwise identical individuals. As long as inital differences in the level of self-confidence are correlated with the socioeconomic background (as a large body of empirical evidence suggests), self-confidence turns out to be a channel through which education and earnings inequalities are transmitted across generations. Our theory suggests that cognitive tests should take place as early as possible, in order to avoid that systematic differences in self-confidence among equally talented people lead to the emergence of gaps in the accumulation of human capital.