A book cipher is a cipher in which each word or letter in the plaintext of a message is replaced by some code that locates it in another text, the key.
A simple version of such a cipher would use a specific book as the key, and would replace each word of the plaintext by a number that gives the position where that word occurs in that book. For example, if the chosen key is H. G. Wells's novel The War of the Worlds, the plaintext "all plans failed, coming back tomorrow" could be encoded as "335 219 881, 5600 853 9315" — since the 335th word of the novel is "all", the 219th is "plans", etc. This method requires that the sender and receiver use the exact same edition of the key book.[1]
This simple version fails if the message uses a word that does not appear in the text. A variant that avoids this problem works with individual letters rather than words. Namely each letter of the plaintext message would be replaced by a number that specifies where that letter occurs in the key book. For example, using the same War of the Worlds book as the key, the message "no ammo" could be encoded as "12 10 / 50 31 59 34" since the words with those positions in the novel are "nineteenth", "of", "almost", "mortal", "might", and "own". This method was used in the second Beale cipher. This variant is more properly called a substitution cipher, specifically a homophonic one.
Both methods, as described, are quite laborious. Therefore, in practice, the key has usually been a codebook created for the purpose: a simple dictionary-like listing of all the words that might be needed to form a message, each with the respective code number(s). This version is called a code, and was extensively used from the 15th century up to World War II.