Two 12-year-old Sydney boys have been charged after allegedly raping a young girl at a primary school in northern Sydney.

The schoolboys were charged at police station on Tuesday after allegedly raping a younger female student last month, police said.

The girl is reportedly six years old.

One of the boys was charged with four counts of aggravated sexual assault and two counts of sexual intercourse with a child under the age of 10. He was granted bail and is due to appear before the children's 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 is due to appear at a children's court in October.

Parents and carers of students at the school are being notified of the incident and NSW police are working closely with the Department of Education and Family and Community Services to ensure support is available at the school.