I recall the first time I noticed voluntary segregation happening with my dc. We were on a family vacation with another family, at their holiday home on a lake. My DS was 6 and DD was 3. There were 2 other children, a boy 10 and a girl, also 6. Before we left, I figured the two 6 y.o.'s would play together most naturally, and they would include the 3 y.o. some of the time to make a small group. I thought age/developmental stages would be the most important factor in play. In fact, despite the age differences, the 2 boys spent all of their time together and the 2 girls played together, if they weren't all playing as one group.
Now, my dc were in Montessori and spent their days in multi-age classrooms, so maybe it shouldn't have surprised me that age didn't matter and that gender seemed to be a significant factor. However, up until that vacation, they seemed to play in mixed gender groups with boys and girls equally. It was interesting to observe the gender split that happened immediately and without any thought that summer. It wasn't unacceptable to mix and there were no recriminations about it, but I didn't see any real desire to mix either. So the voluntary separation can happen quite young.
The separation doesn't necessarily persist though. Through the years, they've had quite a few friends from both genders. Now, as teens, they have both had girls and boys as friends and they all hang out together. DD is 15 and her closest friends are all girls, but DS has quite a few friends who are girls (as opposed to romantic girlfriends).
As for how to handle mixed groups at school, one thing I'd be very careful about is the teachers' attitudes. In middle school, it seemed like a favourite classroom tactic was using a "Battle of the Sexes" as a motivation tool. One teacher (male) in particular fostered a lot of nasty ill-will between the boys and girls by turning everything into a contest - academic work, fundraisers, yard clean-up... Every boy in the class was convinced the teacher favoured the girls. The teacher thought he was being sensitive to the special learning needs of the girls and encouraging their leadership etc. etc. It was an excellent example of good intentions, based on social research cited in the Separate Classrooms thread, being badly implemented and creating more problems than it solved.