In the "age of fairy tales", when the World was whole, Kingdom Hearts was believed to be the source of all light. It was protected by its counterpart, the χ-blade. Many came to desire the power of light contained within Kingdom Hearts, and they clashed together, wielding the Keyblades they created in the image of the χ-blade. Their greed and jealousy introduced darkness into the World, and in the aftermath of this Keyblade War, the χ-blade was shattered into pieces, darkness covered the World, and Kingdom Hearts disappeared within the darkness.
Before Kingdom Hearts Birth by SleepEdit
As a Keyblade wielder, Xehanort studied the legends surrounding Kingdom Hearts, the χ-blade, and the Keyblade War. After he became a Keyblade Master, he searched for a way to reforge the χ-blade, summon Kingdom Hearts, and restart the Keyblade War in order to recreate the World as a balance between light and darkness.
To further his plans, he extracted the heart of his pupil, Ventus, to create Vanitas. He left Ventus with his fellow former student, Master Eraqus, with the intention of having him and Vanitas clash in the future to create the χ-blade.
Kingdom Hearts: Birth by SleepEdit
In Kingdom Hearts Birth by Sleep, set ten years prior of the first game, Kingdom Hearts appears similar to the one in Kingdom Hearts II, but with blue in the sky above the Keyblade Graveyard. The graveyard is what remains of a conflict called the Keyblade War, which was many years before Birth by Sleep. Keyblade Masters affiliated with Light and Darkness, fighting to create the legendary χ-blade, a Keyblade capable of unlocking Kingdom Hearts. These Keyblade Masters failed and destroyed themselves; their remaining weapons littering the world.
Some time after, a Keyblade Master named Master Xehanort planned to create the χ-blade. In his reports, he explains his views of the equilibrium of Light and Darkness and how they countered those from Master Eraqus's. Opposite to Eraqus's beliefs of light being absolute, Xehanort saw that light couldn't exist without darkness. He noticed that light was prevailing and that darkness was excluded too much and created a goal to destroy the current system of light and recreate a new system of darkness, and be able to reorganize the worlds.
In the end, he succeeded in creating the χ-blade by manipulating his former apprentice, Ventus, and his dark counterpart, Vanitas. With the creation of the χ-blade, Xehanort stopped his battle with Terra, released his heart by striking his chest with his own Keyblade, and used the power of Kingdom Hearts to transfer his heart into Terra's body. After he obtained access to Terra's body, a part of Terra's emotions went into the discarded armor, forming the Lingering Will. Xehanort lost in a battle and fainted, unable to proceed his plans with Kingdom Hearts because of his memories being sealed.
In the first game, Xehanort's Heartless, Ansem, Seeker of Darkness, and the horde of villains led by Maleficent sought out Kingdom Hearts. Both wanted to draw out the darkness that surrounded it in order to gain immeasurable power and knowledge.
To accomplish this, Maleficent searched for the Seven Princesses of Heart, maidens with hearts that had no darkness within them. When brought together, these princesses would reveal the final keyhole and the way to Kingdom Hearts itself. Maleficent attacked many worlds with the Heartless and managed to capture all seven. During all of this, she was being used by Xehanort's Heartless.
Sora traveled to Hollow Bastion a second time and sealed the Keyhole. Xehanort's Heartless was still a threat, however, so Sora and company went to the End of the World, where, in the eternal abyss, lay the unlocked door to Kingdom Hearts.
After battling Xehanort's Heartless, they reached the endless abyss to where the Door to Darkness lay, with the Realm of Darkness and Kingdom Hearts waiting behind it. The door was opened, in hopes for supreme darkness by Xehanort's Heartless, but instead was revealed to be light. It destroyed him, but the darkness surrounding Kingdom Hearts threatened to overwhelm the Realm of Light. To stop the threat, Sora closed the Door to Darkness, trapping Riku and Mickey Mouse on the other side. The destroyed worlds were restored, along with the barriers between them, preventing any Heartless from invading the Realm of Light.
Kingdom Hearts: 358/2 DaysEdit
Throughout the game, Organization XIII tires to collect hearts by destroying Emblem Heartless, to create their own Kingdom Hearts within The World That Never Was. Even though their goal is to become complete beings, Xemnas, Xehanort's Nobody, intends to become one with Kingdom Hearts itself.
Kingdom Hearts IIEdit
By the time Sora learns that hearts released by a Keyblade, the Kingdom Hearts above the Castle That Never Was is nearly complete. But other than Xemnas, a revived Maleficent also seeks out Kingdom Hearts once more and refuses to let the Organization get to it first.
Due to Ansem the Wise's attempt to seal Kingdom Hearts away, the explosion that sends him to Dark Meridian and restored Riku's original form left a hole in Kingdom Hearts, causing hearts to rain down over the world and becoming Heartless as soon as they touch the darkness. Xemnas attempted to have the Keyblade wielders help him again, though their refusal forces him to take drastic action to carry out his plan of becoming one with Kingdom Hearts.
A new door, much like the Door to Darkness, appears and allows Sora and his companions to enter Kingdom Hearts. But Xemnas had already absorbed Kingdom Hearts' power and attempts to use it against his opponents after transforming Kingdom Hearts' dimension into a replica of the World That Never Was. What happens to Kingdom Hearts after Xemnas's defeat is unknown, but can be thought that it no longer exists.