Allegory is (a) a figure of speech or a type of writing; or (b) a mode of interpretation of texts.
Allegory as a type of writing
An allegory is a story or other text in which all the characters and details have a meaning in a context which is quite different from the context that is explicit in the text. For example, George Orwell’s Animal Farm appears to be a fairy story about talking animals, but it is actually about the history of the Soviet Union and the corruption of the communist ideal, and many of the characters can be identified as particular members of the Soviet leadership.
Allegory in this sense probably does not exist in the Old Testament. Candidates might include Jotham’s fable about the trees in Judg 9:7-15. But since the different trees do not correspond to different characters in the story of Abimelech and the Shechemites, it is a parable rather than an allegory. A closer fit is Nathan’s parable of the rich man and the poor man’s ewe lamb (2 Sam 12:1-4), where the rich man is David, the poor man Uriah, and the lamb is Bathsheba. However, since the situation is basically the same as the real-life situation, it does not count as allegory. The traditional interpretation of the Song of Songs makes it an allegory of the mutual love of God and Israel, or Christ and the Church or the believer. But it is unlikely that this was the intended meaning. Rather, we have here an example of allegorical interpretation.
This treats a text which may or may not be intended as an allegory as if it were one, like the traditional interpretation of the Song of Songs. In ancient and medieval Christian biblical study this is one of the standard modes of interpretation. For example, Origen (184/5–253/4 CE) treats the story of the crossing of the Red Sea in Exodus 14 as an allegory of baptism. The Israelites are the candidates for baptism, and Egypt is the life of sin which they must leave; Pharaoh and the pursuing Egyptians are the devil and his forces; and all the place names are given a meaning which fits his interpretation.
Hayes, John H., ed. Dictionary of Biblical Interpretation. 2 vols. Nashville, TN: Abingdon Press, 1999.