A spinning top with flat facets, known as a "totum" or "teetotum," is an ancient form of randomizer, but a emerged as a particularly popular gambling tool in Germany ca. 1500 CE. From there it spread throughout Europe as an alternative to dice. And whereas dice had long since established themselves as being labeled with numbers 1-6, and were at least sometimes used in pairs as is most familiar today (originally through the game of Hazard, which dates back to the thirteenth century), teetotums could be customized for the specific game rules the players wanted to use.
It's a bit surprising, given that advantage, that the teetotum died out. Or rather, I should say, very nearly died out, since modern ones are quite well-recognized throughout the western world. We just don't call them teetotums anymore, favoring the Yiddish word dreidel instead.
Early teetotums most often come in four- and six-sided versions, though other numbers are certainly well-attested. Stamped or painted into each side is a letter, generally the initial of a Latin word indicating what action to take in the game. The most common set seems to have been the letters D, N, A, and T, for depone "pay in" (put a coin into the common pot), nihil "nothing" (nothing happens), aufer "take" (take a coin from the pot), and totum (take all the coins in the pot; this is the origin of the name of the game and the top itself), but others are well-documented. Sometimes the A was replaced by another letter that could mean payment (P seems to be common, from pone) and the D was interpreted as dimidium "half," meaning the player takes half of what is in the pot. Plenty of others were invented, and for some of them, we have no idea what they meant anymore. Some teetotums even had eight sides, each with a different abbreviation.
If you've ever played Glückshaus, by the way, this will start to feel familiar, and may well be related to that dicing game's central mechanics of paying in coins, removing them, and collecting some or all of the whole board.
And, indeed, the teetotum was most popular in Germany, also the origin of Glückshaus. So it comes as no surprise that sometimes the letters were replaced with vernacular versions, where they stood for the same actions in German. This is where we see the origins of the modern dreidel; in Yiddish, the actions for a Latin NTDP teetotum became nisht "nothing," gants "all," halb "half," and shtel ayn "put in." As the Ashkenazi Jewish community adopted the teetotum, many were more familiar with Hebrew letters for their language than with the alphabet of their Christian neighbors, and so these were abbreviated with nun, gimmel, hei, and shin as seen on dreidels to this day.
But how did the dreidel become associated with Hanukkah? There are a number of legends and two solid theories. The most popular, but historically mistaken, story of the origin of the dreidel is that it was created as a reminder of the Hanukkah story; this does live on in a tradition of reading the letters as standing for נס גדול היה שם nes gadol hayah sham "A great miracle happened there." (In fact many Haredi dredels in Israel change the last letter to pei so that it may be read as "A great miracle happened here" instead.) But it's pretty clear that interpretation postdates the letters, which have everything to do with the Yiddish language and the non-sectarian teetotum game. Some historians suggest that gambling with teetotums became more popular at Christmastime when they were still used by Christians, which naturally transitioned to Hanukkah, though this just pushes the question of why it developed a seasonal association into a different culture. Another theory, not mutually exclusive with the first, is that its connection to Hanukkah is a reflection of the now largely forgotten Jewish holiday of Nittel Nacht.
The seventeenth century was a time when Christians' treatment of Jews was at an especially low ebb, and Christmas became a particular annual focal point for the persecution. A number of historic pogroms of the seventeenth through nineteenth centuries began on Christmas Eve or Chritsmas Day, and during the late sixteenth and seventeenth centuries in many parts of Germany there were laws forbidding Jews from going out in public from Christmas Eve until Epiphany.
Jewish tradition holds that study of the Torah brings benefit to all of humanity. Not wanting to have a night they saw as profaned by Christian oppression drag this benefit down, many rabbis discouraged Torah study on Christmas Eve. And for self-defense, it was seen as useful for the entire Jewish community to gather together. Thus, sometime around 1600, Nittel Nacht was born, a peculiar custom of the German Jewish community in which the people would gather every Christmas Eve. Over time, some rabbis added other requirements, such as suggesting that particularly devout Jews avoid sleep lest they dream about Torah study, and forbidding sexual relations on the grounds that children conceived on Christmas Eve were particularly prone to apostasy. So, the Jewish population needed something to spend a long winter night doing - something that definitely wasn't studying the Torah or having sex. One answer was work in preparation for the Sabbath, but mostly they seem to have preferred more social activities. Card games are known to have been popular (and in some Jewish families remain a Hanukkah tradition to this day). While there is no specific historical record of it, dice and dreidels would likely have been a substantial part of the occasion also.
As the nineteenth century brought about an effort toward rapprochement between the Christian and Jewish faiths and the birth of the Reform movement in Judaism, Nittel Nacht celebrations became scarce. Today, very few Jewish communities still hold them, and for those unusually conservative ones which do, the loss of the entirely secular conditions that brought them about has turned them into another example of a major theme in other Jewish holidays: the ultimate survival of and triumph over oppression. And for the rest of the religion the winter partying hasn't died; it's just been merged into the nearest holiday in the Jewish calendar. With it, an old German gambling game lives on, now played by children with chocolate coins for eight nights each year.