Melatonin is a hormone that helps you sleep well. A consequence of modern life is that the amount of melatonin your body makes, and when it makes it, is often different from how it used to be in the environment of our ancestors. Taking some extra melatonin before you go to sleep can ensure there is enough melatonin available in your body for you to sleep well.
The bottom line
Melatonin is safe1,2 and cheap. The optimal dose is 0.3mg shortly before going to sleep2. The reason much larger doses are available is patents2 covering lower doses.
Other reliable sources are The Mayo Clinic3 and the NIH4.