Hundreds of years prior to her birth, Princess Celestia learned of a prophecy: a unicorn of immense power would one day ascend to alicornhood and lead Equestria and beyond into a new age of hope and friendship. A unicorn that she would personally take under her wing as her personal student. Over the centuries, Princess Celestia would come across many powerful unicorns that she took under her wing with all of them not working out such Sunset Shimmer who was power hungry and fled to the human world or Sunburst who, while very knowledgable about magic, had a disability that made him struggle with casting powerful spells and led to him running to the Crystal Empire in shame.
Twilight Sparkle was born to Night Light and Twilight Velvet in Canterlot, being 5 years younger than her older brother, Shining Armor. After seeing Princess Celestia perform magic at the Summer Sun Celebration in Canterlot, Twilight developed a strong desire to study magic. To that end, her parents applied for her to study at Celestia’s School for Gifted Unicorns. At the entrance exam, Twilight was told to use magic to hatch Spike’s egg, but she was unable to cast a spell. A moment after she gave up, Rainbow Dash’s sonic rainboom startled her and caused her magic to go out of control. Princess Celestia witnessed Twilight’s magical abilities and made Twilight her personal student.
Twilight began to attend Celestia’s school. During her time there, she befriended a group of unicorns: Twinkleshine, Lemon Hearts, Minuette, and Moon Dancer, being especially close to Moon Dancer. But the more she got into her studies, the more she isolated herself from her friends, even going so far to blow Moon Dancer off when the unicorn decided to get out of her comfort zone and throw a small party. Concerned with her asocial behavior, Princess Celestia sends Twilight Sparkle to ponyville to oversee the Summer Sun Celebration there as well as try to make friends.
Upon arriving in Ponyville, she ends up meeting Applejack, Rainbow Dash, Fluttershy, Pinkie Pie, and Rarity. The celebration is interrupted when Nightmare Moon, Celestia’s nemesis, returns to power and threatens to bring eternal night to Equestria. Twilight and the rest of the Mane Six discover the Elements of Harmony and use them to transform Nightmare Moon back into Princess Luna. Princess Celestia gives Twilight permission to remain in Ponyville to study the magic of friendship.
Over the next year, Twilight Sparkle stayed in Ponyville with her new group of friends where they learned lessons in friendship that they would all report back to Princess Celestia. As Twilight advanced in her studies, the Alicorn sisters decided that Twilight Sparkle was ready to advance the next part of her destiny. After Twilight Sparkle finished Starswirl the Bearded's spell, showing that she understood friendship better than Starswirl did, Twilight proved she was ready and ascended to alicornhood.
Now an alicorn princess, Twilight had trouble adjusting to her new reality. Compared to the other three alicorn princesses, Twilight didn't understand at first what she was meant to do. But soon enough, Twilight came to understand what part she was supposed to play: Twilight Sparkle, the Princess of Friendship.