Black holes across a broad range of masses play a key role in the evolution of galaxies. The initial seeds of black holes formed at z ~ 30 and grew over cosmic time by gas accretion and mergers. Using observational data for quasars and theoretical models for the hierarchical assembly of dark matter halos, we study the relative importance of gas accretion and mergers for black hole growth, as a function of redshift (0 < z < 10) and black hole mass (103 M⊙ < M < 1010 M⊙). We find that: (i) growth by accretion is dominant in a large fraction of the parameter space, especially at M > 108 M⊙ and z > 6; (ii) growth by mergers is dominant at M < 105 M⊙ and z > 5.5, and at M > 108 M⊙ and z < 2. As the growth channel has direct implications for the black hole spin (with gas accretion leading to higher spin values), we test our model against ~20 robust spin measurements available thus far. As expected, the spin tends to decline towards the merger-dominated regime, thereby supporting our model. The next generation of X-ray and gravitational wave observatories (e.g. Lynx, Athena and LISA) will map out populations of black holes up to very high redshift (z ~ 20), covering the parameter space investigated here in almost its entirety. Their data will be instrumental to providing a clear picture of how black holes grew across cosmic time.