a, Schematic of social isolation paradigm. Adult fruit flies with social experience were subjected to social isolation or group enrichment for 7 days before sleep is measured using Drosophila Activity Monitors. Social isolation is housing 1 fly per vial. Group enrichment is housing 2, 5, 25 or 100 flies per vial. b, Sleep profile (displayed as the average proportion of time spent sleeping in consecutive 30min segments during a 24hr LD cycle, Mean±SEM) of flies after social isolation or group enrichment of different group sizes for 7 days. c–g, Raster plot of sleep bouts of 20 individual animals after social isolation (c), group enrichment in a group of 2 animals (d), group enrichment in a group of 5 animals (e), group enrichment in a group of 25 animals (f) and group enrichment in a group of 100 animals (g). Each row is an individual animal, with each colored bar representing sleep bouts in a 24hr LD cycle. h–k, Quantification (Mean±SEM with individual data points) of daily total sleep (h), daytime sleep (i), ZT0-4 sleep (j) and nighttime sleep (k) for flies after social isolation (Iso) or group enrichment (Grp) of different group sizes. For b and h–k, N=23–30 animals; ordinary one-way ANOVA followed by Tukey’s multiple comparison tests; means sharing the same letter are not significantly different. For N and P values, see the Source Data.