Andrew Beattie’s offending came to light when he was arrested in May 2010 after more than 1,300 indecent images of children were found on his home computer.
The victims came forward to report the assaults, which took place at Selkirk High School in the Borders in the 1990s.
Passing sentence, Sheriff Donald Corke told Beattie, 62, his offences were a “gross breach of trust and abuse of power”.
He added: “You must understand the public revulsion that a teacher should possess such images.”
Jedburgh Sheriff Court was told Beattie had been the victim of sexual abuse in the past and had a “lifelong interest in pubescent boys”.
Beattie, a teacher at Selkirk High School for 30 years, previously pleaded guilty at Jedburgh Sheriff Court to having the indecent images at his home in Hawick on 14 May, 2010.
He also admitted indecently assaulting a 14-year-old boy while working as a teacher at the secondary school between April and August 1991 and also performing a sex act on a 15-year-old male pupil between April 1995 and May 1996.
A previous court hearing was told how a joint operation run by Lincolnshire Police and the Child Protection Centre led to an e-mail address used by Beattie to download indecent images of children. A credit card also linked him to a website.
The court was told that Beattie’s bedroom computer hard drive was examined and more than 1,300 indecent images of young boys were found.
Following publicity about the case, two former pupils came forward to say they had been indecently assaulted by him.
Defence advocate Shelagh McCall said Beattie had the prospect of a prison sentence hanging over him for the past two years. She said: “He has suffered a great deal of anxiety and stress and ill-health.”
Ms McCall added that experts had rated the prospects of him reoffending as “relatively low”.
Ms McCall said: “He is deeply ashamed. He recognises it was his job to make amends and has done everything he can to make amends.”
She said he had resigned from his job as soon as the allegations came to light without forcing disciplinary issues. He had been ostracised by his neighbours and had his car vandalised.
Ms McCall said Beattie had recently been baptised in the Pentecostal Church which provided him with a great deal of support and accountability.
Sheriff Corke imposed jail sentences of 16 months and eight months for the indecent assaults, as well as four months for the child porn – all sentences to run concurrently.
He also imposed an extended sentence of three years and four months to provide supervision after he was released from prison and recommended to Scottish ministers that Beattie was unsuitable to work with children.
Beattie, of Longhope drive, Hawick, was put on the Sex Offenders Register for ten years.