It has been known since 1904 that, in humans, diverse cognitive traits are positively intercorrelated. This forms the basis for the general factor of intelligence (g). Here, we directly test whether there is a partial genetic basis for individual differences in g using data from seven different cognitive tests (n = 11,263-331,679) and genome-wide autosomal single-nucleotide polymorphisms. A genetic g factor accounts for an average of 58.4% (s.e. = 4.8%) of the genetic variance in the cognitive traits considered, with the proportion varying widely across traits (range, 9-95%). We distil genetic loci that are broadly relevant for many cognitive traits (g) from loci associated specifically with individual cognitive traits. These results contribute to elucidating the aetiology of a long-known yet poorly understood phenomenon, revealing a fundamental dimension of genetic sharing across diverse cognitive traits.