On 7 October 2015, 21 days before the schoolboy Bailey Gwynne was stabbed to death at Cults Academy in Aberdeen, his 16-year-old killer made a simple seven word Google search.

It read: “How to get rid of someone annoying.”

This was by no means the sole reason the unnamed teenager responsible was sentenced to nine years in prison for culpable homicide, but it is a fact that many newspapers ran with in their headlines. The Sun called the Google search “chilling”. Anyone who has delved two pages too far into the results for “ricin” after a particularly riveting episode of Breaking Bad will feel the same – for entirely different reasons.

“It is now a common occurrence for computers to be analysed along with telephones and for all social media to be interrogated,” says Brian McConnachie QC, a criminal defence barrister. “It is almost commonplace for there to be reference to at least one of these in any serious trial.”

Still, unless the search in itself is illegal, it’s unlikely you’ll be arrested or imprisoned for your curious googlings about murder or human body disposal (note: feed to pigs). But if you’re already – rightly or wrongly – a suspect in a case, your search history can be considered very damning evidence.

“A one-time search can be evidentially significant and multiple searches are not required,” says McConnachie. “However, searching for a term on many occasions – like Lolita or such like – may make it easier to invite to the court to make an adverse inference.”

Bailey Gwynne’s killer didn’t just wonder how to shake off someone irritating, and also made a variety of other incriminating searches such as “Aberdeen stabbings death per 1,000?”, “illegal knives uk” and “difference between homicide and murder”. But his defence lawyer, Ian Duguid QC, claimed in court that the searches had been taken out of context and selectively chosen by the prosecution.

“It seems like no one has followed through in these searches to see what they are,” he said, referring to a video called “14-year-old Bronx student stabs bully to death outside school” that turned out to be a cartoon. Charles Bruce, the computer forensics analyst that examined the laptop, admitted that he only investigated the searches, not the links clicked on or their content.

If you don’t find it worrying that your internet history can be twisted and cherry-picked to defend or defame your moral character then congratulations, enjoy Farmville. But are you right to be worried? McConnachie notes that although a one-time search can be considered incriminating, timing is important.

“It's unlikely that searches from long ago would be used in respect of a recent crime as relevancy would be more difficult to establish,” says McConnachie, who defended Rachel Fee, a woman jailed for abusing and murdering her toddler, Liam. Before Liam’s death, Fee and her partner Nyomi had googled “can you die from a broken bone”, “morphine for children”, and “can wives b in prison together?”. During their trial, they pleaded guilty on a count of neglect.

“I have little doubt that it was the searches that made both accused accept knowledge of the fact that Liam had a broken leg and that in failing to obtain treatment they were therefore guilty of neglect,” says McConnachie. “Timing is also significant in relation to the date of the crime. Obviously googling ‘how to treat a broken leg’ is much more significant the day after someone potentially has their leg broken than six months before that date.”

There are also various defences that lawyers can use against this sort of evidence. McConachie notes that the accused can claim to simply have been curious about a matter. If they share a computer or a device, they can also claim they didn’t make the search.

“The main thing generally would be that you cannot tell from the search who searched it – although there may be passwords involved,” he says.

These are strong defences, should you ever find yourself framed for murder trying to explain the time you googled “how to destroy human teeth” to a jury. As long as you didn’t google it a hundred times the night before a body was found behind your house, you should be safe, right? Yes, provided the technology used to analyse your search history actually worked.

In July 2011, Casey Anthony was found not guilty of murdering her two-year-old daughter Caylee. Many members of the public were outraged, as Anthony’s partying personality and alleged inappropriate grief were considered evidence of her guilt. Others could not dismiss the fact – referenced extensively in her trial – that an investigation of Anthony’s home computer revealed she had searched the word “chloroform” 84 times.

Except she hadn’t. The software used by the witness John Dennis Bradley had been faulty, and he later discovered that the world “chloroform” had only been searched for once. The website Anthony then clicked on was about the use of the organic compound in the 19th century.

The case illustrates that not only can search histories be faulty, they can also be very prejudicial. If I told you that Justin Ross Harris searched how long it takes an animal to die in a hot car a month before his son died in the same way, would you assume his guilt? If you’re an infrequent googler, maybe. If you Google every question that pops into your head, maybe not.

If all this has scared you into jamming down the delete button in a panicked frenzy, stop. McConnachie notes that investigators can and do recover deleted searches. “Indeed the fact of it being deleted is possibly even more incriminating as it could be said to demonstrate that you have something to hide,” he says.

There are two lessons here. If you are a criminal: use a library computer. If you are just curious, researching a crime novel, or fact-checking your favourite TV drama: don’t be a criminal.

“If we intend to get involved in crime or if we have been involved in crime then beware your internet search history,” says McConnachie.