A long time ago...
- Human SOULs are extremely strong thanks to a power called "determination". Humans' physical bodies are much stronger than the magical bodies that monsters have. However, because of the "determination" of the human SOUL, it lingers outside of the body, even after death. Humanity discovers that monsters have the ability to absorb human SOULs after the human's death. It would turn the monster into an immensely powerful being.
- Fearing this power, the humans wage war on the monsters. The humans are victorious and trap the monsters inside a mountain with many twisting and winding caverns known as the Underground. They seal the entrance with a magical Barrier.
Sometime later...
- Toriel and Azgore create "HOME" in the Ruins of the Underground.
- A human child who hates humanity falls into the Underground. Asriel Dreemur, son of Toriel and Azgore, finds the child and carries him back to the castle. This is the child that you name at the start of the game. You do not play as the child that you name.
- Asriel and the human become like brothers. However, the human grows sick, and dies. Asriel, torn by grief, absorbs the human SOUL. Asriel transforms into a being of immense power, but immediately realizes that the human SOUL is also in control of their shared body. The human decides to carry his body to the village, where he wants to use their new power to destroy all of humanity (for reasons unknown to Asriel). Asriel resists, and when he dies, his consciousness becomes scattered.
- Most monsters decide to move out of the Ruins and into the rest of the Underground. They establish "NEW HOME" at the capital.
After Asriel's death...
- Azgore in his grief orders that all humans that fall into the Underground thereafter would be killed. Not truly wanting to fight or kill anyone, he says that he will destroy the barrier and humanity once he had obtained seven human souls, and secretly hoped that none would ever appear.
- Toriel, disgusted with Azgore, leaves him and seals the Ruins off from the rest of the Underground.
- Alphys meets a ghost (whose name is unknown... Papyrus incorrectly names her Happstablook, the happy ghost, but this is stated to be incorrect) at a "human fan club" meeting. After a while, Alphys and the ghost become friends, and Alphys constructs a robotic body for the ghost. Thereafter, the ghost is known as Mettaton.
- Azgore orders Dr. Alphys to run experiments on the nature of the SOUL. In her experiments, Alphys discovers "determination" and tries to inject it into monsters so that their SOULs would be more powerful. However, the magical bodies of the monsters are unable to handle the power of "determination" and melt into one another, creating distorted monstrosities. Dr. Alphys hides the failed experiments from the rest of the Underground.
- Six humans are killed and their SOULs captured.
- Azgore begins training Undyne.
- Dr. Alphys runs tests on creating a "vessel" to contain and control the seven human SOULs when they are obtained. She decides to use Azgore's favorite type of golden flower to store the vessel. Alphys becomes curious as to what would happen if a being without a SOUL gained the will to live, and began running tests.
- Asriel's consciousness finds its way into the vessel. Confused and scared, Asriel escapes the laboratory and finds sanctuary in Azgore's castle. Without a soul, Asriel is unable to feel love or compassion, and is terrified by this. From this point on, Asriel is known as Flowey.
- Flowey attempts to kill himself, deciding that a world without love is worse than no world at all. He discovers his ability to save, load, and reset the timeline. He repeatedly attempts to kill himself, before loading in fear of what would happen to a soul-less consciousness after death.
- Flowey uses his powers to help people. Being bored with that, he tries a number of other things. Eventually learning exactly how people would react to certain things or events, he begins to grow bored, sadistic, and demented. He adopts a "Kill or be killed." policy.
- Undyne begins training Papyrus.
The beginning of Undertale...
- A child named Frisk, who is very similar in nature and appearance to the original human child whose soul was absorbed by Asriel, falls into the Underground. Flowey loses the ability to save and load, and being extremely lonely, immediately attaches himself to Frisk, and calls him after the name of the original child.
Then, depending on the ending you get, different stuff happens. I won't spoil that. All of the information here is not inferred... its pieced together from information you get directly from each ending, secrets, etc.