Allegory is usually defined as a story written to parallel a situation outside of the story. The term is understood to have several meanings with varying degree of strictness.
As a literary device, an allegory in its most general sense is an extended metaphor.
More strictly speaking, in an allegory, characters and actions inside the story must match up with those of an "outside" situation.
The book Animal Farm is a classic example of allegory. The characters in the book are intended to parallel real people from the Russian communist revolution and events of the book are meant to match up with actual events from the revolution.
The idea of creating intentional correlations between the story and a situation outside of the story is critical to the definition of allegory. If elements of the story do not directly represent elements of an outside situation, the story is not an allegory.
Fables and parables are like allegory in certain ways and can be confused with them.
Allegories often are written with a specific comment or point in mind, like fables and parables. Yet in fables the characters do not need to match up with anything outside of the story. A fable or parable can be written to demonstrate a point of wisdom or morality, like "The Tortise and the Hare", but the characters do not represent or match up with any particular people outside of the story. They stand for ideas. This is symbolism, not allegory.
Simply put, an allegory is an extended metaphor. A metaphor is something that stands for something else. Therefore, an allegory is a work (book, short story, movie, poem) that stands for something else outside of the actual work.
Usually, work that is an allegory has many symbols throughout that represent something bigger than what they actually are. The work may have been written to have many layers of meaning. I like to tell my students that allegories are written about one thing to show readers something else.
There are quite a few examples that you may be familiar with, which will hopefully clear up any confusion. Arthur Miller wrote The Crucible about the Salem Witch trials in the 1600's, but it was really about the Red Scare and McCarthyism in the 1960's. He wanted to use the events of the Salem Witch Trials to show audiences and readers that what McCarthy did to innocent people was no different than what the Salem government did to innnocent people. The accusers in The Crucible were symbols for the accusers in the real life "witch hunt" of the Red Scare.
Many popular folk and fairy tales are allegories. They are stories about specific characters, but really tell us something about ourselves and teach a lesson. "The Tortois and the Hare", for example, is an allegory for how we should go about things in life. The tortois represents someone who takes his time and does things right, and the hare represents someone who rushes things and ends up losing because of it.
The important thing to remember with regard to allegory is that there are many symbols entertwined to represent something much bigger than what the work is actually saying. It may seem simple at first, but if you look at what it is trying to say, you will see that is has a whole other layer of meaning.
Allegory is a literary device using a name to represent something bigger. For example, if a person's name is Liberty or Freedom, this would be an allegory for that ideal. A literary example would be John Bunyan's Pilgrim's Progress where the main character's name is Christian. The story in itself is a religious allegory.