Ever since Edgar Allan Poe created the first detective, the detective story has been a staple of literature. Though early detective stories often featured a group of amateur crime sleuths trying to find the murderer, later detective stories introduced the hard-boiled private investigator. For anyone who wishes to learn how to write in the crime genre, the detective story provides a staple formula to follow.
Introduce the crime. The crime should be introduced in the first three chapters, as it is the basis for the entire story and that which the plot revolves around. You can use a chapter or two for background or setting up the crime but if you place the crime too late into the story, the reader will quickly lose interest.
Introduce the detective. Typically the victim of the crime or someone related to the victim calls the detective, who is a private investigator, and asks him to investigate the crime. The detective is typically a middle-aged man who is cynical, brash, difficult to deal with and yet possesses a brilliant, logical mind that other characters envy. The detective should also have a bad, addictive habit such as drinking or smoking. If the detective isn't a private investigator but an amateur, then the detective will typically be a main character caught in the middle of the crime who displays these same characteristics.
Introduce the prime suspects and the antagonist. All the prime suspects should be introduced early on in the story, after the crime has been committed and the detective introduced, so that the reader can attempt to guess who is the guilty party. Prime suspects typically have annoying personalities or destructive habits that make them disliked by the reader.
Keep the reader in the dark. If the reader solves the crime before the end of the story, then the reader will regard the book as simple and not feel challenged. Don't let the reader into the thoughts of the prime suspects or the antagonist. Give the illusion that characters are living lives off the page so that the reader can make guesses as to what the characters are doing when the detective isn't around to watch them.
Provide clues. Even though you're keeping the reader in the dark, you should also provide clues so that the reader can attempt to guess who committed the crime and how it was committed. If the ending comes completely out of left field, then readers will feel cheated, so the writer should provide just enough information to allow the reader to try to solve the crime without giving them enough information to actually solve it.
Create a dangerous scenario for the detective. Before the end of the story, the detective is usually placed in mortal peril by the antagonist. Once the detective figures out who committed the crime, the antagonist tries to murder the detective or sets up a trap for him. The detective must escape the trap or defeat the antagonist so he can reveal to the other prime suspects who committed the crime.
Have the detective solve the crime. The detective solves the crime by using logical deduction, not through a deus ex machina, a supernatural occurrence or an accident. The detective's brilliance should be revealed to the reader with his ability to take all the different clues and put them together.
Answer all unsolved questions. Avoid leaving the reader wondering what happened in a specific instance by making sure everything is explained at the end of the story. The reader should end the story feeling satisfied at the conclusion, not confused.