Nietzsche introduces the thought in The Gay Science through a demon who poses the question in the night. The demon asks: how would you react if told that you must live your life again and again, eternally? If the thought crushes you, your life does not bear repeating. If you can embrace it — even will it — you have achieved the highest affirmation.
Eternal recurrence is not primarily a cosmological hypothesis. Whether it is literally true matters less than its function as a test. It asks you to live in such a way that you would affirm the infinite repetition of this very life. It is an extreme form of amor fati — love of fate — applied to every detail of one's existence.
Some scholars, notably Maudemarie Clark, have argued that Nietzsche did not hold eternal recurrence as a literal doctrine but used it as a thought experiment. The question remains contested.