The formation of stars above about 20 M⊙ and their apparently high multiplicity remain heavily debated subjects in astrophysics. We have performed a vast high-resolution radial velocity spectroscopic survey of about 250 O- and 540 B-type stars in the southern Milky Way which indicates that the majority of stars (>82 per cent) with masses above 16 M⊙ form close binary systems while this fraction rapidly drops to 20 per cent for stars of 3 M⊙. The binary fractions of O-type stars among different environment classes are: clusters (72 ± 13 per cent), associations (73 ± 8 per cent), field (43 ± 13 per cent) and runaways (69 ± 11 per cent). The high frequency of close pairs with components of similar mass argues in favour of a multiplicity originating from the formation process rather than from a tidal capture in a dense cluster. The high binary frequency of runaway O stars that we found in our survey (69 per cent compared to 19–26 per cent in previous surveys) points to the importance of ejection from young star clusters and thus supports the competitive accretion scenario.