This will cover the lore of the Sonic series, from the events before Sonic 1 to Sonic Adventure 2.
This will not cover the cartoons and comics as they contradict the games, and therefore, are not canon.
All information used belongs to their respective owners.
Let's Begin!
Prologue
Modern-day Earth is destroyed.
Millions of years later, animals evolve, becoming intelligent and developing unusual abilities. Plate tectonics reshape the planet, and humans team up with animals to rebuild civilization, and reconstruct mythological cities and better technology.
The world is governed by a few small nations and a huge militaristic one: The United Federation.
Dr. Gerald Robotnik, a geneticist, is enlisted by the United Federation to secretly create the Ultimate Lifeform (later revealed to be Shadow) aboard the Space Colony A.R.K.
Instead, he makes first contact with an alien race (The Black Arms) and makes a secret trade with them; alien DNA for Chaos Emeralds.
But because the Chaos Emeralds are still hidden somewhere and Gerald does not have them, he is given fifty years to find them.
After Gerald created Shadow, the United Federation shut down the Ark, killing and quieting all who knew about Project Shadow, and even subduing the Prototype of the Ultimate Lifeform that Gerald had worked on; the Biolizard.
Gerald's daughter, Maria Robotnik, was also killed by the United Federation.
However, before Gerald could enact his revenge against the government, he was imprisoned.
Forty-five Years Later...
Sonic the Hedgehog
Dr. Ivo Robotnik (better known as Eggman), a roboticist and grandson of Gerald, plots to usher an utopia by building a robot army and a space station: The Death Egg.
He plans to power it with Chaos Emeralds (that are still hidden somewhere). He discovers they are located on South Island, so he conquers it, and enslaves the animals by roboticizing them so they can assist him in his search for the Emeralds.
South Island is the home of Sonic the Hedgehog. He races across the island to liberate the animals, get the Emeralds first and safeguard them. He defeats Eggman and flees to West Side Island, where he meets Miles "Tails" Prower for the first time.
Sonic the Hedgehog 2
Eggman offers Sonic a trade: the kidnapped inhabitants of West Side Island for the Chaos Emeralds. Sonic refuses.
Eggman invades the island, grabs the Emeralds and powers up the Death Egg. Sonic infiltrates it, reclaims the Emeralds and powers it down.
Sonic 3 and Knuckles
Eggman crash lands on Angel Island, which is the home of Knuckles the Echidna, guardian of the Master Emerald.
Eggman convinces Knuckles that Sonic is an Emerald thief, so Knuckles attacks Sonic and steals the Emeralds from him, allowing Eggman to relaunch the Death Egg AND steal the Master Emerald.
Sonic destroys the Death Egg and reclaims the Chaos Emeralds.
Sonic Adventure
With the Master Emerald in hand, Eggman learns of an ancient legend about it, which prompts him to shatter it, unleashing the Chaos monster.
They travel the world for Chaos Emeralds, which Eggman feeds Chaos with to make him stronger. But in the end, Chaos turns on Eggman.
Sonic defeats Chaos and Eggman escapes.
Sonic Adventure 2
Eggman then learns about the Ultimate Lifeform from his grandfather's diary.
He infiltrates the research facility and awakens Shadow, who agrees to steal the Chaos Emeralds and rendezvous at Space Colony A.R.K.
Once there, Shadow reveals Gerald's world-destroying eclipse cannon.
Eggman uses it to blow up half the moon as demonstration he's holding the world ransom so he can establish his utopia by force.
In other words, he's demanding a ransom by threatening to destroy Earth with the cannon if the government does not allow Eggman to establish his utopia.
Shadow initiates the 'A.R.K. Collision Course with Earth' program, a part of Gerald's unfulfilled revenge plot against the United Federation whereby the A.R.K. collides with Earth and destroys it.
Realising his mistake, Shadow helps Sonic save the planet (Eggman too!).
Epilogue
The Black Arms aliens finally return for their Chaos Emeralds from Gerald (but he's no longer alive), so they invade the planet to find them, creating the perfect opportunity for Eggman, Shadow and Sonic to rush and grab the Chaos Emeralds.
And together, they exterminate the alien threat with Gerald's eclipse cannon.
End
Of course, not every single detail of the lore is included here, so this anthology ain't 100% accurate.
But hopefully, you might've gotten the gist of it!
Thanks for reading, and I'm signing this off with a picture of edgy Tails!