A Queens middle-school teacher who sent nude photos of himself to a 14-year-old former student landed six months behind bars Tuesday.

Disgraced former math teacher Michael Cognato copped to a plea deal to dodge a harsher sentence of up to seven years in prison.

But since he had talked with the girl after his arrest , violating an order of protection, the judge upgraded his sex-offender status from Level 1 to Level 2, meaning that, among other things, he must register his whereabouts with the state for life instead of 20 years.

“It’s not like stealing candy from a store,’’ Judge Gia Morris chided Cognato’s lawyer, Scott Gross, when he argued that his client hadn’t initiated the calls between the pair.

Morris also sentenced Cognato to 10 years probation.

The perv’s mother, who was in court and wearing two cross pendants, hissed at the prosecutor as she left, “I do not appreciate what you did to my son.”

The mom later told The Post, “My son is a good son.

“He is not an ax murderer.”

Cognato had been the teen’s eighth-grade teacher at IS 93 in Ridgewood. After she graduated, he sent sexually explicit texts and nude photos of himself to her. She reciprocated with ones of her own, and soon, the pair was exchanging X-rated videos of themselves, prosecutors said.

The girl’s mom discovered the exchanges and alerted cops.