Belshazzar's feast, or the story of the writing on the wall, chapter 5 in the Book of Daniel, tells how Belshazzar holds a great feast and drinks from the vessels that had been looted in the destruction of the First Temple. A hand appears and writes on the wall. The terrified Belshazzar calls for his wise men, but they are unable to read the writing. The queen advises him to send for Daniel, renowned for his wisdom. Daniel reminds Belshazzar that his father Nebuchadnezzar, when he became arrogant, was thrown down until he learned that God has sovereignty over the kingdom of men (see Daniel 4). Belshazzar had likewise blasphemed God, and so God sent this hand. Daniel then reads the message and interprets it: God has numbered Belshazzar's days, he has been weighed and found wanting, and his kingdom will be given to the Medes and the Persians.
That very night Belshazzar, the Chaldean [Babylonian] king, was killed. And Darius the Mede received the kingdom […]
— Daniel 5:30–31[1]
The message of Daniel 5 is the contrast it offers between Nebuchadnezzar and Belshazzar:
According to John J. Collins, Belshazzar's feast is a legend conforming to the subgenre of the "tale of court contest", complicated by the inclusion of Daniel's indictment of Belshazzar's pride and his failure to honour the God of Israel. As a result, the tale has a double ending, in which Daniel is first showered with rewards and honours for interpreting the omen, and the king is then punished to fulfill the sentence pronounced by Daniel.[3]
From the story the idiom "to be able to read the writing on the wall" came to mean being able to see from available evidence that doom or failure is inevitable, and "the writing on the wall" itself can mean anything portending such doom or failure.