We randomly assign more than 6,000 students from 150 primary schools in Bangladesh to work on math assignments in one of three settings: individually, in groups with random schoolmates, or in groups with friends. The groups consist of four people and are balanced by average cognitive ability and ability distribution. While the achievement of male students is not affected by the group assignment, low-ability females assigned to groups outperform low-ability females working individually. The treatment is particularly effective when lowability females study with friends. To rule out sorting effects, we show that random groups with identical compositions to those of friendship groups do not produce similar effects. Our study thus documents that placing students into study groups with their friends may improve learning, especially for low-ability females.