Rabbi Yosef Karo, the author of the Shulkhan Arukh, wrote an earlier work called the Beit Yosef, and is often referred to by its title. Karo asked a question several Rishonim (leading medieval rabbis) asked before him and other leading rabbis asked afterward: If the oil in the Temple menorah lasted seven days when there was only enough oil to last one day, why do we commemorate this miracle of oil on Hanukkah by lighting menorahs for eight days? Shouldn't we light them for seven? Shouldn't Hanukkah only be seven days long? The answer to Karo's famous question is actually quite simple – so simple, in fact, that almost all haredim don't have any idea what the real answer to Karo's question is.
Here's the answer in eight parts:
1. Hanukkah does not commemorate a miracle of oil. There was no such miracle. All contemporaneous accounts of the first Hanukkah make no mention of such a miracle and for hundreds of years afterward, the sources are silent about this 'miracle of oil.' We first hear about it in Talmudic times about 600 years after the purported miracle supposedly took place.
2. Hanukkah celebrates the capture and rededication of the Temple by the Hasmoneans (Maccabees), who had hoped to have the Temple liberated and ready for use in time for Sukkot and Shemini Atzeret – which together are 8 days long. But the capture and cleanup took longer than expected, and the Hasmonean's rededication celebration took place about two months after Sukkot-Shemini Atzeret was over. As part of the celebration, the Hasmoneans lit torches and lamps in the Temple compound (something Jews really liked). Ancient contemporaneous sources confirm this.
3. The first Hanukkah was intended as a one-off holiday that was a combination of a celebration of the military victory and the Temple's rededication on one hand and a kind of make-up holiday for the Sukkot and Shemini Atzeret holidays which had been missed due to the war on the other, but by the second year it had morphed into its own folk festival roughly analogous to America's Fourth of July. People lit lights – usually one light – each night for eight days and partied.The Hasmoneans decided to continue having a yearly commemoration of their victory and of the Temple liberation, and called it Orot – lights. (The name is also confirmed by early sources.)
4. The early rabbis were ambivalent about the holiday and about the Hasmoneans, and that ambivalence grew to outright opposition by late in the Hasmonean reign.
5. The people kept celebrating Hanukkah anyway, because the early rabbis were almost completely irrelevant.
6. During the First Revolt against Rome, and after the Temple was destroyed and that revolt was crushed, and then again during and after the Bar Kokhba revolt, Jews viewed Hanukkah much like American's might have viewed July Fourth during the War of 1812 when the Capital and White House were burned by the British.
7. As the Land of Israel became less and less Jewish due to persecution, hardships and conversion, Hanukkah (likely still called Orot) was a wistful symbol of hope for the remaining Jews, and was likely a popular folk holiday among Jews in Babylon and elsewhere in the Middle Eastern Diaspora.
8. At about this time, the rabbis began teaching about a "miracle of oil" and tried to use it to convert the Hasmonean's celebration of a military victory and a make-up holiday for a missed Sukkot and Shemini Atzeret into a rabbinic holiday that proved God's power. This became the holiday we now call Hanukkah.