Like many topics of psychological research, the explanation for friendship is at once intuitive and difficult to address empirically. These difficulties worsen when one seeks, as we do, to go beyond "obvious" explanations ("humans are social creatures") to ask deeper questions, such as "What is the evolved function of human friendship?" In recent years, however, a new window into human behavior has opened as a growing fraction of people’s social activity has moved online, leaving a wealth of digital traces behind. One example is a feature of the MySpace social network that allows millions of users to rank their "Top Friends." In this study, we collected over 10 million people’s friendship decisions from MySpace to test predictions made by hypotheses about human friendship. We found particular support for the alliance hypothesis, which holds that human friendship is caused by cognitive systems that function to create alliances for potential disputes. Because an ally’s support can be undermined by a stronger outside relationship, the alliance model predicts that people will prefer partners who rank them above other friends. Consistent with the alliance model, we found that an individual’s choice of best friend in MySpace is strongly predicted by how partners rank that individual.