Necrons were once a living species, proud and intelligent, but became corrupted by the machinations of the C'Tan, the ancient star gods of the Warhammer Universe, and cast aside their mortal bodies for those of cold, immortal machines. Having laid dormant for eons, these terrible machines now awaken with the intent to snuff out the plague that is mortal life.
Necrons are extremely powerful and capable warriors, armed with horrifying Gauss weaponry capable of ripping through an unfortunate target layer by molecular layer. Worse, Necrons can never truly be destroyed in combat; the shattered remains are teleproted back to their tombs to be repaired (even Necrons that had been reduced to puddles of slag).
Necrons are led in battle by Necron Lords, members of the Necron's former race who have kept both their intelligence and glimmers of their former personalities, or, rarely, by their C'Tan masters.
Before the Necrons, came the Necrontyr, a human race born on a planet in which their solar system revolved around a binary star and emitted continuous amounts of radiation to the planets the Necrontyr inhabited.
The Necrontyr had such a short lifespan that death was common and no one feared such thing, but they were however, an intelligent and powerful race, conquering land masses and other planets in their solar system and others. The Necrontyr kept order with their many dynasties and with their Triarch system, in which the Silent King ruled and only answered his subjects through the chain-of-command with the two Phaerons who ruled alongside the Silent King. Anything that the Silent King would hear would go from the dynasties, to their dynasty rulers, to the Phaerons, and then the Silent King, to which he answers by talking to the Phaerons and gives the solution down to the leader, and you get the idea.
All seemed well and order was slowly withering away until the dynasties rivaled each other, and due to their short lifespans, intellect, and power, a civil war would begin and start the chain reaction from the Necrontyr to become the dreaded, Necrons.
The Silent King was also tired of living for only such an amount of time before dying, that the Silent King had asked the Old Ones, an ancient race that is speculated to be the predecessors to the Eldar, for the path to immortality, as they were the ones who knew it and kept it locked away for themselves. The Silent King also knew about the devastation of the civil war and eventually waged war on the Old Ones, which would be known in Eldar history as the War in Heaven, due to both races being technologically advanced and powerful.
The War in Heaven
Long story short, the War in Heaven was a war that began by the Necrontyr to unify their race. This battle had been long forgotten since it began and only through Eldar stories, were they remembered and thought to exist. This war did exist, and was the war that turned the Necrontyr into the Necrons.
Despite the advanced technology, unification, and resources the Necrontyr had, especially with low lifespans, they couldn't win this battle due to the Old Ones having the mastery of the Warp, sending their fleet and forces from one part of the galaxy to the other, and so on and so forth. The Necrontyr knew this battle couldn't be won, but they turned over to the C'Tan, a bunch of star eating entities that they worshipped to be gods.
In short, the Necrontyr created bodies and used their superior technology for the C'tan gods to enter and live with the Necrontyr and hopefully fight alongside and win the War. The C'tan agreed to fight alongside the Necrontyr due to the Old Ones also being their oldest enemies, and because they were tired of eating stars, and enjoyed the taste of living souls more than they did with stars.
The C'tan offered the Necrontyr many things to fight the Old Ones on a war that seemed one-sided, but the most important gift was the path to immortality. The Necrontyr were pleased and praised the C'tan as they created machines that would turn themselves into soulless, metal endoskeletons that use a very unique metal called Necrodermis, meaning Living Metal, which is unbelievably strong and flexible. When the last of the Silent Kings, Szarekh, became a Necron, he had a fragment of what he used to be, and looked around, taking a moment to wonder what he had done; he had sacrificed his entire race to become soulless beings that would no longer feel anything they would feel again, and that their entire race was wiped out.
The Silent King and the metal living bodies of necrodermis would call themselves, the Necrons.
The Tide Turns
The Necrons, now having god tier weaponry and bodies that could revive themselves, were now ready to face the Old Ones, as they began pushing them back and taking over some of the Warp drives with the C'tan's help, and used their technology against them. The Old Ones, wiped out after the entire battle would be a victory celebration for the C'tan, but not so much for the Necrons, now knowing what they have done.
The Necrons turned against the C'tan during their short-lived victory celebration, containing most of them in shards and locking them up in what is now called the Tesseract Labrynth, in which the Necrons use to gain their former gods' essences to utilize and destroy their enemies.
One of the other c'tan than escaped was the Void Dragon, who eventually found its way to Mars, became imprisoned by the Imperium of Mankind, and became to be the one known as the Machine God, Omnissiah, for it knows all, and is the reason why the Imperium has some technological advancements.
During the C'tan betrayal however, the Necrons have been cursed with the Flayed curse, which made unfortunate incoming Necrons to have an unsatiable hunger and "need" to survive by eating the meat and flesh off their victims. Like all necrons, unfortunately, the Flayed Ones can't really open their mouths, or eat in general.
The Silent King's final order was to go into a deep sleep set for 60 million standard years.
It is the 40th millennium, some of the many Necrons have awakened from their long slumber to retake what was theirs, and to strive. However, some tomb worlds and crypts have been damaged and the Necrons there are forced to go into a deep sleep for all of eternity.
Now, there are many younger races that stand in the Necron's way to domination, such as the Eldar, using the Warp as their weapon, making them an age-old enemy of the Necrons, and many more.
The Silent King had quoted saying that eventually, all Necrons would succumb to insanity and madness due to the feeling of being a metal skeleton and not being what they were. Some, if not, many Necrons have already succumbed to the madness and have been bent on galactic, or even worse, universal domination that cannot be cured, and is only treatable by death.
Some Necrons however, remain sane, at least for now they do. Sane Necrons have actually allied with their enemies to combat a larger threat at hand (i.e., a recently awakened dynasty allied with the Space Marines in order to save a planet from Tyranids).
However, other insane Necrons seem helpful, they have worse plans in mind. An example comes from a Chaos Daemon invasion on one particular planet, until the Necrons come by and save the planet's inhabitants, until the Harvest began and they were turned into Necrons. Another story comes from the Dark Eldar; they went as a raiding party to raid the Orks, only to find no one but death in the Ork camp. The Necrons then fired upon the Dark Eldar, until the Dark Eldar were forced to retreat, hardly anyone from the DE raid party survived.
The Imperium's Encounter
The first time the Imperium (those are the humans) have encountered the Necrons is the Massacre at Sanctuary 101. The Canoptek dynasty invades the Sanctuary that is held by the Sisters of Battle, who are in essence, nuns with guns, armor, and a huge devotion to the God-Emperor of Mankind (don't ask me how there became a monotheistic religion that ruled Earth and beyond). The Canoptek, armed with god-tier weaponry and armor had killed ALL the Sisters in the area, leaving absolutely zero people alive.
The Imperium of Man encountered them in a brutal event, known as the Yuctan Incident. Keep in mind, the Imperium have no clue who and what the Necrons even are, or if they exist at this time. This became a naval battle between the Necrons and the Imperium, as the Necrons destroyed 6 escort ships, 1 light cruiser, but left 1 cobra-class destroyer left (also note, the Necrons teleported away after destroying the 7 ships, they didn't want to do anything to the destroyer apparently). The Necrons then completely eradicated all human life in the Yuctan system, beginning their first harvest.
After a recording of the Sanctuary 101 Massacre, the Imperium was shocked and basically said, "Oh emperor, why..." and found out how terrifying the Necrons were in combat. This also triggers another incident to occur.
A Space Marine squad was dropped into a planet, but only 5 minutes in, the ship that drops them off, loses all contact of the space marines.