The allegory of the cave is probably the most famous of all the passages in The Republic. It is being used to show the difference between the world of senses and the world of forms. Forms are immutable and timeless, unlike what we see/feel/sense in the actual world, which are shadowy, unreliable reflections of their Forms. Plato believes that humans can never really 'see' the Forms, but there are some that are able to 'see' them more clearly than others.
The allegory he uses in the cave is that the prisoners who are chained to the wall and forced to watch the shadowy figures and scenes that can be seen through a curtain - the shadowy figures (which we know are not real), becomes their view of reality.
If a prisoner was released and forced to see the 'real' world as we know it, the brilliance of it would be painful and difficult for the prisoner to understand. At first the man would want to return to the cave and the comfort of his own reality, but once he became used to it he would eventually realize that he had been living a life of illusion in a world that he didn't even know that the sun existed. He may go back and try to teach his fellow prisoners about his new reality, but if he attempted to release them to experience what they would see as madness, they would try to kill him.
He uses this allegory to explain why philosophers are so often mocked, they have had a glimpse of the Forms and the people that they are trying to explain those ideas to find it incomprehensible. Most people are stuck in the shadowy world of the senses, like the prisoners are in the cave.
The forms/ideals were what the man in the cave "looked" at when he came out - the sun. This allegory is an education, a paidia, in the way to the ideal.