The tradition is thought to have begun with French settlers, continuing a custom dating back to 12th century France, when a similar cake was used to celebrate the coming of the three wise men bearing gifts twelve days after Christmas, calling it the feast of Epiphany, Twelfth Night, or King's Day.
Though the cakes are baked in many shapes now, they were originally round in shape to portray the circular route taken by the Kings to confuse King Herod who was trying to follow the wise men so he could kill the Christ child.
The cakes usually contain a bean, pea, or a figurine symbolizing the baby Jesus. In 1871 the tradition of choosing the queen of the Mardi Gras was determined by who drew the prize in the cake. It is definitely considered good luck to the person who gets the figure, and that person usually holds the next King Cake party.
The Rex Krewe, a Mardi Gras parade organization, chose the festival's symbolic colors, and since 1872 the colors have been used to tint the cake's icing. The colors of the King Cake are purple for justice, green for faith, and gold for power.