Music is widely recognised as a human universal, yet there is no agreed explanation for its function, or why and when it evolved. I summarise experimental evidence that the primary function of musicking lies in social bonding, both at the dyadic and community levels, via the effect that performing any form of music has on the brain's endorphin system (the principal neurohormonal basis for social bonding in primates). The many other functions associated with music-making (mate choice, pleasure, coalition signalling, etc) are all better understood as derivative of this, either as secondary selection pressures or as windows of evolutionary opportunity (exaptations). If music's function is primarily as an adjunct of the social bonding mechanism (a feature it shares with laughter, feasting, storytelling and the rituals of religion), then reverse engineering the problem suggests that the capacity for music-making most likely evolved with the appearance of archaic humans. This agrees well with anatomical evidence for the capacity to sing.