Many warriors wanted light from Kingdom Hearts. They made keyblades based on the X-Blade which guarded Kingdom Hearts and coexisted with it. The war broke the X-Blade into 20 pieces: seven of light and thirteen of darkness. Kingdom Hearts was swallowed by darkness since the X-Blade broke. The hearts of children helped the world illuminate albeit separated.
When Xehanort arrived at the Land of Departure, he was interested in the Keyblade War. Xehanort made a plan to remake the historical event. Since Xehanort is old, he wanted to find a vessel so he can extend his life. He once picked Ventus who failed. Xehanort extracted Ven's darkness and created a man named Vanitas. Xehanort wanted Ven and Vanitas to fuse to forge the X-Blade. Xehanort noticed the weapon was forged. Xehanort used Terra as his vessel. Xehanort came across Terra's keyblade armor and battled it. Since it was 1/10th complete, the X-Blade broke and Xehanort got amnesia. However, Xehanort made back up plans. Braig who is another vessel of Xehanort helped Xehanort regain his memories. Xehanort, Braig, Dilan, Ienzo, Aeleus and Even worked on creating Heartless until Ansem banned their work. They later banished Ansem to the Realm of Darkness. Xehanort regained his memories and stabbed Braig. He declared that is not Xehanort but "Ansem". Xehanort worked on Ansem's reports until he became a Heartless and a Nobody named "Ansem" and "Xemnas", respectively. Ansem was tasked to work with Maleficent, Xehanort's ally to find the Princesses of Heart and open the door to the blackened Kingdom Hearts along with the worlds he have destroyed. Xemnas is tasked to create Organization XIII for a specific reason: round up a bunch of emptied husks, hook them up to Kingdom Hearts and transform them into 13 Xehanorts. However, through weakness of body, will or trust, most of the members were inadequate. Thus naturally, they never had a chance to attain their goal. Even this was to be expected. As a backup plan, Ansem time traveled to Xehanort as a teenager at Destiny Islands to find 12 future versions of Xehanort. Both of Ansem and Xemnas' plans were foiled by Sora. The deaths led to the return of Master Xehanort. At the Mark of Mastery exam, Xehanort and his comrades revealed their plan to Sora and his friends. Xehanort and his friends retreated back to their normal time to get prepared for the final battle. Yen Sid wanted seven keyblade wielders to protect the princesses. The Guardians of Light are: Sora, Mickey, Riku, Aqua, Terra, Ventus and Kairi (who got her ability when inadvertently touching Aqua's keyblade).