A York man who fantasised about raping children during sordid internet chats and downloaded thousands of indecent images of youngsters has been spared jail.

Paedophile Garry William Anderson, 28, was initially arrested in March last year when police swooped on a property in York and found more than 2,000 indecent images on his devices.

Anderson had shared some of those images - including some rated Category A, the worst kind of such material - with “like-minded perverts” on the Telegram app, York Crown Court heard.

Prosecutor Jennifer Coxon said Anderson was arrested again in February this year and admitted downloading and distributing indecent images.

He was bailed, but by April he was chatting online to a man he thought was a like-minded individual. However, that man turned out to be an undercover police officer.

Anderson told the officer he fantasised about raping, sexually abusing and punishing children.

He was arrested a week later at his grandmother’s property in St Stephen’s Road, York, where he had been living in a shed in the back garden.

Officers searched the shed and seized two mobile phones on which they found just over 100 indecent images of children, 42 of which were Category A. He admitted to officers that he was sexually attracted to children of a certain age but claimed the online chats were “all fantasy”.

He was charged with several counts of making indecent images, two counts of distributing illicit child imagery and publishing an obscene article between January 2015 and April this year. He admitted the offences and appeared for sentence after being remanded in custody.

Ms Coxon said the children depicted in the images were as young as three. There were hundreds of victims.

She said that Anderson was initially arrested on March 7 last year after police received intelligence that a Snapchat user matching his profile had been downloading indecent material.

They seized two mobiles on which they found just over a thousand Category A indecent photos and videos of children, some of which he had shared with others. Forensic analysis of the devices revealed that Anderson had downloaded a further 1,012 images.

He had stashed the images in a hidden, password-protected folder via an app called Keep Safe.

Defence barrister Jordan Milican said Anderson was about 18 when he started downloading the illicit material.

“At the time, he was living with his grandmother and lived in a shed at the bottom of the garden,” added Mr Milican.

“The relationship between the two had irretrievably broken down following the death of his grandfather some years ago.”

Anderson had turned to cannabis since his bereavement and became “incredibly isolated”.

It was while “under the influence of drink or drugs” that he disappeared down the “rabbit hole” of the “darkest part of the internet”.

Judge Simon Hickey described as “revolting” the images downloaded and shared by Anderson.

He said that “hundreds of children were either abused, humiliated or degraded".

However, he recognised Anderson’s “frankness” with police, his “genuine remorse”, his “troubled” background and the fact that a relatively small number of images had been distributed.

He told Anderson: “You recognise your own perversion and you want to do something about it. I know that there is no rehabilitation…in our prisons because they are simply far too overcrowded.”

Mr Hickey said that weighing all the mitigating factors against the nature of the offences, he was prepared to suspend the inevitable jail sentence and give Anderson a “golden opportunity to get out of the prison estate (and) put this offending behind you".

The two-year jail sentence was suspended for 24 months. Anderson was ordered to sign on the sex-offenders’ register for 10 years and was made subject to a 10-year sexual-harm-prevention order to curb his online activities and limit his contact with children.

In addition, he was ordered to complete a 43-session offender programme, 30 rehabilitation-activity days and a 12-month drug-rehabilitation course.