I have heard this story many times from different monks, always with minor variations, but I will try to recount it as faithfully as I can. But please check other sources if you want exact details (or post if you have them).
Siddhartha Gautama lived somewhere around 563-483 BCE, no one seems to know exactly. He was a Prince, son of the King of the Sakyas, in today's Nepal more or less.
According to the story, when he was born, his father asked three wise men to tell him what awaited his son. Two of them said he would either become the Universal King or the next Buddha. But the third one, an old man, said he was sure he would become the next Buddha.
Now, for a better understanding of the rest of the story, let me briefly explain the concept of "the Buddha" (yes, it is either the Buddha, or a Buddha, never just Buddha - it is not his name).
First, "a Buddha". The word "Buddha" in Sanskrit means "awakened one". Some translate it "enlightened one", but if I recall my Sanskrit correctly, "awakened one" is a better translation.
The idea is that there were many Buddhas before Gautama, and will be in the future. In Mahayana Buddhism the word Buddha is used somewhat more loosely than in Theravada. In Mahayana anyone who has realized full awakening is a Buddha. The Theravadins call such a person an arhat or arhant. For the purpose of this story I shall use the "stricter" meaning as used by the Theravadins.
According to the stricter interpretation a Buddha is one who realizes nirvana during the period of complete darkness (spiritual, not physical), after the previous Buddha has been completely forgotten. The Buddha, then, is the person who comes to complete understanding of the Universe, and all reality, and is thus the first of many, after a kalpa (a very long period of time) to break away from the cycle of rebirth, or samsara.
Now, back to the story. When Gautama's father heard the three wise men, he decided it would be better if his son did not become the next Buddha, but rather if he grew up to be the Universal King (remember, his father was a king).
He completely isolated young Gautama from the outside world. The Prince was never to see anything or anyone unhappy or suffering. All he was allowed to experience was the life of pleasure within the palace walls (that would include the royal gardens, too, he was certainly not a "prisoner", or at least not to feel like one).
For some fifteen years, Prince Gautama experienced nothing but fun and pleasure. But as he was maturing, he realized this kind of life was not fulfilling, and would not bring him happiness. One night, he secretly asked his faithful servant and friend (whose name I do not remember), to saddle up a horse for him and to take him outside the palace.
At the risk of death penalty, out of friendship and devotion, the servant did as the Prince asked. As they were riding, they saw an old man walking slowly by the road. As Gautama had never seen an old man, he was horrified by the looks of old age, and asked the servent what happened to that man. The servant explained the man was old. "But how did it happen to him?" "Everyone grows old," the servant explained. "Will I grow old, too?" Gautama asked. "Yes, you will."
Now, in some accounts all of this happened on the same night, in others on three different occasions, but that is pretty irrelevant. Then they saw a sick man, and had a similar conversation. Finally, they saw a corpse, and Gautama learned about death and that everyone, including himself would eventually die.
Moved by the experience, Gautama cut his hair with his sword, and sent his servant back to the palace. He turned to a very strict way of life, life of penance, hardship, and self-denial. He studied, for many years, with many Hindu teachers of the era.
But he still did not find happiness. He thought, the life of pleasure does not produce happiness, the life of self-denial does not result in happiness. What does?
He sat under a tree, crosslegged, which is how he is commonly portrayed in statues. He was determined he would not leave his position until he found the answer. Finally, after several days, he came to a full understanding of all reality. It was at that point that he became the Buddha.
He was then approached by several of his formal companions in the life of self-denial. They believed he turned away from the way of the righteous, and came to reprimand him. But they were totally overcome by his new, awakened, appeal. Instead, they asked him to teach them. He taught them about the Middle Way of avoiding extremes. He taught them the Four Noble Truths (there is suffering; suffering is caused by craving; overcoming craving ends suffering; there is an eightfold path that leads to the overcoming of craving and to the end of suffering). He taught them the Eightfold Path. They became the first Buddhists, and were later followed by many.
The story continues for many, many years, but I will end here.