Bobby belonged to John Gray, who worked for the Edinburgh City Police as a night watchman, and the two were inseparable for approximately two years. Then, on 15 February 1858, Gray died of tuberculosis. He was buried in Greyfriars Kirkyard, the graveyard surrounding Greyfriars Kirk in the Old Town of Edinburgh. Bobby, who survived John Gray by 14 years, is said to have spent the rest of his life pining by his master's grave.
Bobby died in 1872 and could not be buried within the cemetery itself, since it was consecrated ground. Instead he was buried just inside the gate of Greyfriars Kirkyard, not far from John Gray's grave. His headstone states, "Greyfriars Bobby - died 14th January 1872 - aged 16 years - Let his loyalty and devotion be a lesson to us all".