It is unknown where the AllSpark originally came from, though some sources say that it was created by a mysterious power for an unknown reason. The AllSpark was responsible for creating the planet Cybertron, and the Transformers that inhabited it. It first created the Dynasty of Primes (and, according to several Revenge of the Fallen adaptions, the Matrix of Leadership), and well as Transformer workers to serve them.Generations later, when the Cybertronian War between the Autobots and the Decepticons began for control of the AllSpark, Optimus Prime launched the Cube into deep space in a last-ditch attempt to keep it out of Decepticon hands. However, Megatron followed the AllSpark, which eventually landed on Earth in around 10,000BC, in what would later become the Colorado River.
Some twelve thousand years later, the AllSpark was discovered in the Colorado River in 1913, and Hoover Dam was built around it to hide its presence while Sector Seven studied the Cube. S7 eventually realized that the Cube emitted radiation which could bring inanimate machinery and technology to life.In 2007, ninety-four years after the AllSpark was discovered by humans, the Dam came under attack from the Decepticons. To get the AllSpark to safety, Bumblebee somehow interacted with the Cube to cause it to shrink to a much smaller size. The AllSpark was quickly taken to nearby Mission City, where Sam was instructed to take it to the top of the highest building for evac. Stumbling as he ran, Sam fell and struck the AllSpark on the ground, causing it to release a wave of energon radiation which brought several nearby machines to life. Upon reaching the top of the building, Sam was confronted by Megatron, but refused to turn the cube over to him, and was sent toppling from the building. Optimus Prime came to his rescue, and during the battle that followed between Prime and Megatron, the Autobot leader told Sam to merge the AllSpark with his spark in order to destroy it. However, Sam instead merged it with Megatron's spark, destroying both the Decepticon leader and apparently the AllSpark.
Though the Cube was destroyed, two shards survived and retained some of the AllSpark's power. While one shard was found in the remains of Megatron's spark chamber by Optimus, and subsequently kept at Diego Garcia under maximum security, the other was embedded in Sam's jumper, and remained there, undiscovered for another two years.In 2009, two years after the Cube was destroyed, Sam found the AllSpark fragment in his shirt (which he had kept untouched in his closet as a memory since the Battle of Mission City). When Sam examined the shard, it transferred the AllSpark's knowledge of the Dynasty of Primes into Sam's mind. The fragment then burnt through the floor and into the kitchen below Sam's bedroom, releasing a burst of energy which brought the kitchen appliances to life.
The other shard, meanwhile, was kept by N.E.S.T. on Diego Garcia, until Soundwave discovered the shard's location and dispatched Ravage and Reedman to retrieve it. The two were able to steal the shard from Diego Garcia and take it to the Laurentian Abyss, where it was used by Scalpel to revive Megatron.