A teacher at Eton College sexually touched pupils during regular "nocturnal visits" while they were alone, a court has heard.
Matthew Mowbray, 49, denies nine counts of sexual activity with a child against four boys and one girl over a period of several years.
He has pleaded guilty to downloading hundreds of indecent images of children, Reading Crown Court was told.
He has also admitted one count of voyeurism.
Mr Mowbray, of Locks Heath, Southampton, was dismissed from his role at the boys' boarding school, near Windsor, Berkshire, following his arrest.
Prosecutor John Price QC said Mr Mowbray would pay regular "nocturnal visits" to partly-clothed boys "for his own sexual gratification".
He said the defendant purported "to engage them in conversation about college matters, would touch or stroke them on their arms or, through the bed covers, on their upper legs".
It continued even after he had been warned by a colleague, his trial was told.
"If he was prepared to take such risks, with the obvious potential for great harm to his own career and reputation, continuing to do so even in the face of explicit advice from a colleague that he should desist, one is entitled to ask what motivated him to do so?" Mr Price said.
Mr Mowbray has admitted six counts of making indecent images of children, including creating pseudo-images of pupils by superimposing their faces on to the naked bodies of unknown children, the jury was told.
He has also admitted one count of voyeurism relating to a series of covertly filmed images showing a boy getting dressed.
"The prosecution submits that evidence of this activity by Mr Mowbray, proves beyond doubt what was his concealed and true purpose when touching the four boys," Mr Price said.
He added: "That most of those who have complained about Mr Mowbray are boys, may reflect little more than the fact that through his employment he had almost unfettered access to boys of that age, but not so many opportunities to come into contact with young girls."
The trial continues.