This poem is Tolkien’s creation based on the English nursery rhyme Hey Diddle Diddle. The origins of Hey Diddle Diddle are not known, though there are many theories as to what it might mean. Tolkien’s The Man in the Moon Stayed Up Too Late imagines that the lines come from a longer poem, of which only the nursery rhyme now remains.
This is one of the hints in the book that Middle-earth is not supposed to be thought of as an entirely separate fantasy world, but as an ancient legend of our own Earth. At first Tolkien identified the end of the Third Age of Middle-earth as coming about 6000 years before his time, but later changed his mind to state that Middle-earth is our world but “at a different stage of the imagination.” It is therefore more like an alternate version of our world.
The name Middle-earth is a translation of ‘middangeard’, an Old English name derived from the Germanic ‘midgard’, which according to myth is the home of man. It is surrounded by an impassable ocean in which the great sea serpent surrounds the world, holding his own tail in his mouth. Tolkien was influenced by a fragment in Old English that he studied in 1914, which mentioned the names of Earendel and Middle-earth: “Hail Earendel, brightest of angels / above the middle-earth sent unto men.”
For more about Tolkien’s Middle-earth, see the Setting.