Bobby's owner, John Gray, worked for the Edinburgh Police Department (EPD) as a night watchman until he died of tuberculosis on 15 February 1858. He was buried in Greyfriars Kirkyard, the graveyard surrounding Greyfriars Kirk in the Old Town of Edinburgh. Bobby, who survived with John for 14 years, is said to have spent the rest of his life sitting on his master's grave. A more realistic account has it that he spent a great deal of time at Gray's grave, but that he left regularly for meals at a restaurant beside the graveyard, and may have spent colder winters in nearby houses.

In 1867, when it was pointed out that an unowned dog should be put down, the Lord Provost of Edinburgh, Sir William Chambers (who was also a director of the Scottish Society for the Prevention of Cruelty to Animals), paid for a renewal of Bobby's licence, making him the responsibility of the city council.

Bobby passed away 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".