Megatron is the commander of the Decepticons, traditional enemies of the heroic Autobots and the main villain of the entire Transformers franchise - in almost all variations of the cartoon, comic books and movies Megatron is depicted as one of the Autobot's most powerful and relentless opponents. In many ways Megatron could be considered an evil-version of Optimus Prime and sees humans as weak at best and worthy of destruction at worst - unlike most Transformers he has a variety of forms instead of a default one, though he seems to favor tanks and jets in most of the media, though in his original appearances he would often transform into a Modified Walther P38. Megatron can be seen as a ruthless military leader and unlike many villains he was not originally depicted as insane or anarchic in nature - simply being overly aggressive and power-hungry but always having a reason behind his actions (even if others often couldn't understand them).
Like many archenemies Megatron and Optimus Prime have an odd sense of respect for one another despite fighting each other to the death.
There have been times where the two leaders have acknowledged (at least to themselves) that if it wasn't for their differences in ideology they could of been friends - a fact that saddens Optimus Prime but is actually seen to be rather amusing to Megatron. (This is in fact very similar to the relationship between Magneto and Professor Xavier.)
The Transformers: The Movie
Megatron is the secondary antagonist of the film. Taking several years after the cartoon, Megatron wages a full-scale, geniusly orchestrated assault on Autobot City, crippling the Autobot's ranks and killing several high ranking warriors. When Optimus Prime arrived to the battle, he gunned down almost every Decepticon singlehandedly before taking on Megatron himself. Though Optimus got the upper-hand and was readying to execute his nemesis, the Autobot Hot Shot jumped in the way when he noticed Megatron was reaching for a firearm. Megatron managed to incapacitate Hot Shot and mortally wound Optimus before the latter punched the Decepticon commander off the peak of Autobot City. Prime later died from his wounds. Soundwave recovered his fallen leader when the Decepticons began to retreat, but Starscream eventually threw Megatron's wounded body into space to rust before taking the place as the Decepticon leader. Floating in the voids of space, Megatron was summoned by the omnicidal chaos god Unicron where the former was forced to become the latter's apprentice and enforcer. In return, Unicron gave Megatron a new body and titled him as Galvatron.
The original Megatron appears in Season 2 of Beast Wars, where it is revealed that the current Megatron was acting on his predecessor's orders.
Later on, the original Megatron makes a physical appearance in Season 3, where the Predacon Megatron takes the original Megatron's spark, making the newer Megatron obtain his dragon form. However, in a deleted scene, in the series finale, the original Megatron's spark is placed back into his body.
Megatron also has another form in the G1 series named Galvatron, a new body given to him by Unicron.