Two 12-year-old boys have been charged over the alleged assault and rape of a six-year-old girl at a primary school on Sydney's northern beaches.

The girl was allegedly assaulted in the toilet block of the primary school that all three students attended.

The ABC has been told the incident took place in early August and police began investigating the allegations when they were alerted about a week later.

Police said the primary school boys were arrested at Chatswood Police Station on Tuesday.

"Detectives from the State Crime Command's Child Abuse Squad were alerted by the Department of Education following incidents at a primary school," a police statement said.

One boy has been charged with four counts of aggravated sexual assault and two counts of sexual intercourse with a child under the age of 10 and is expected to face court on September 22.

The other boy was charged with two counts of aggravated sexual assault and sexual intercourse with a child under the age of 10 and will face court next month.

Both have been released on bail and they have also been suspended from primary school.

Detectives said parents of students at the primary school are in the process of being notified.