The novel starts with Sherlock Holmes receiving a cipher message from Fred Porlock (pseudonym), an agent of Professor Moriarty. After Porlock sends the message, however, he changes his mind for fear of Moriarty's discovering that he is a traitor. He decides not to send the key to the cipher, but he sends Holmes a note telling of this decision. From the cipher message and the second note, Holmes is able to deduce that it is a book-cipher and that the book used for the encryption is a common book, large (with at least 534 pages), printed in two columns per page, and standardised.
An almanac fits these conditions exactly. Holmes tries the latest edition of Whitaker's Almanac, which he had only received a few days earlier, and fails; he then tries the previous edition. With this almanac, Holmes is able to successfully decipher the message as a warning that "some devilry is intended against one Douglas", a country gentleman residing at Birlstone House.
Some minutes later, Inspector Macdonald arrives at Baker Street with news that a Mr. John Douglas of Birlstone Manor House, Birlstone, Sussex, has been murdered. Holmes tells MacDonald of Porlock's warning, suggesting Moriarty's involvement. However, MacDonald does not fully believe that the educated and well-respected Moriarty is a criminal. Holmes, Watson, and MacDonald travel to Birlstone House, an ancient moated manor house, to investigate the crime.
Douglas had been murdered the evening before. Cecil Barker, a frequent guest at Birlstone House, had been in his room at half-past eleven when he heard the report of a gun, according to his testimony. He had rushed down to find Douglas lying in the centre of the room nearest the front door of the house; a sawed-off shotgun lay across the murdered man's chest. He had been shot at close range, receiving the full charge of the shotgun in the face. His head was blown 'almost to pieces'. Barker had rushed to the village police station and notified Sergeant Wilson, who was in charge of the station. Wilson followed Barker to the house after notifying the county authorities.