After failing to gain control of the Spanish city of Zaragoza, Charlemagne brought his troops back across the Pyrinees to France. As they crossed through the mountain pass at Roncesvalles, the rearguard was set upon by Basques (who likely mistook the army for an attack on their homeland), and many men died. Among them was Hruodland, prefect of the Breton marches.
This is history. These events are known to have happened. Hruodland died on the 15th of August, 778. The facts known to us from the early ninth century, as they appear in one of the first biographies of the emperor. Nothing else at all is known about Hruodland, and little about the battle in which he was killed (though Islamic sources preserve a great deal of information about why Charlemagne and his army were in Spain at that time in the first place). But the memory of the battle persisted oral lore, so that by the twelfth century it was an especially famous moment in the French national memory.
Roland, as the prefect came to be known in French, was esteemed as a paragon of courage and honor in battle, and Charlemagne as his uncle and his worthy liege. Roland, greatest of the Paladins who fought for Carolingian France, is a figure who belongs entirely to legend; any similarities he happens to share with the historical Hruodland are lost to us, save for the fact that both died at Roncesvalles. The battle that kills the Roland of legend is France's Trojan War: rooted unambiguously in history, but with the truth eclipsed by the myth that grew up around it. Like the Trojan War, it is a wistful myth, one that tells of a bygone era of heroes; Roland, like Achilles, falls along with the rest of the great heroes of the French mythos. Also like Achilles, he is presented at once as the epitome of heroism and as someone brought low by his pride and even by his praiseworthy sense of honor. (This is not to say any parallel to Homer's Achilles is intended by the author; while the story of the Trojan War was known in Western Europe at the time of its composition, the text of the Iliad and the details of its portrayal of the subject matter were not.)
The legend of Roland, in its usual form, begins after he is already an illustrious and accomplished knight. He's considered one of a dozen of Charlemagne's knights who merit particular note, known together as the Twelve Peers; the exact makeup of the other eleven varies from one source to another, but Roland is never excluded from the list. He is also relatively young; he's the son of Charlemagne's sister, and if we assume any knowledge at all of the reign of the historical Charlemagne, Roland does not live very long into that period of time. (We should, of course, assume no such thing, but being of the generation younger than the Emperor and having the impulsiveness and boastfulness often attributed to youth, it seems we are not meant to think him an especially old knight.) Roland's stepfather, Ganelon, was a famous baron, but resented Roland for his success and the ego that went with it. Roland, however, saw glory in dangerous exploits, and so nominated Ganelon for an especially dangerous mission: carrying a message to a group of Saracens (Muslims) on behalf of Charlemagne.
The details of the message vary with the telling. The story isn't an especially historical one (in fact the most probable historical source for Ganelon is a bishop who first appears in the historical record in 848, well after Charlemagne's death); while we know what message would have been sent shortly before the historical battle of Roncesvalles in 778, that tells us very little. Per our most prominent early source, the Chanson de Roland, Charlemagne has already conquered all of Spain save the city of Zaragoza; Ganelon is sent to negotiate the terms of that city's surrender. Regardless of the content of the message, the Saracens are not assumed trustworthy or chivalrous, so it is likely they will kill whoever carries it. Ganelon takes his nomination as an insult or a threat.
When Ganelon meets with the Saracens, he arranges a deal: he will ensure that the Twelve Peers are all in the rearguard as Charlemagne pulls out of Spain (it's never quite clear why he will do this, in the version of the story where he rules all but one city of it), and the Saracens will concentrate their attack on that portion of the army. Roland will die, avenging his affront against Ganelon, and the loss of the Twelve Peers will be such a blow to the might of France that, presumably, it's strategically advantageous for the Saracens to do it.
The plan has only one weakness: Roland carries a horn, called the Oliphant, which is able to be sounded so loudly it can be heard for miles. (It's likely that this property is magical in nature.) When Ganelon returns, safe and with a surrender document in hand (one the Saracens have no intention of abiding by thereafter, naturally), returns home and nominates Roland to the prestigious position as head of the rear-guard, suggesting that he take the rest of the Twelve Peers with him. Roland is grateful for the honor of the position, and accepts gladly, leading the Twelve, some unspecified (but probably not trivial) number of other knights, and however many hundreds of men-at-arms that means they're bringing with them.
Then 300,000 Saracen troops sneak up on Roland and ambush him in a mountain pass.
That number isn't mentioned in most of the Matter of France material, because it doesn't make a lick of sense, but it shows up in the extant texts of the Chanson de Roland. There's every implication that the attack was carried out by stealth. For comparison, that's about the present-day population of Pittsburgh, somehow concealing itself in a single pass and attacking a small armed band by surprise. (It's not the only improbable number in the Chanson de Roland, either; the entire work is rich with military details that make no sense in the context of Charlemagne's eighth-century Spanish campaign, but are entirely understandable when one considers it as a work dealing with the First Crusade. While Charlemagne's full military might was comparable, numerically, to the forces that fought the American Civil War and eclipsed even the figures quoted in Crusades-era legend, at no time could he amass that many to fight as a single coherent unit, nor could any of his sundry opponents.) We can only assume Roland's famous ego somehow blinded him to the existence of a major city right next to his path that hadn't been there when he entered the country.
This, of course, makes it even more impressive when Roland and his men successfully defeat all of Pittsburgh in battle, by the standards of medieval poets, but I'm getting ahead of myself. Roland's companion Oliver (whose relationship with Roland is written about in the Chanson de Roland in such tones as to make some modern scholars wonder whether that particular author intended them to be interpreted as a couple, though they clearly are not in many other sources) suggests immediately that this would be a good time to sound the Oliphant and call back the main body of Charlemagne's forces. Roland refuses, seeing it as more honorable for the dozen of them (and, of course, the uncounted men-at-arms who accompany the knights) to win this fight themselves. The Archbishop of Rheims, who is among the Twelve Peers, says last rites for them all, and then they fight. One by one, the men of the rear-guard die; Roland still does not sound his horn. Finally, Oliver is slain, and Roland stands alone among all the Franks against a much-reduced Saracen cohort. At this time, at last, he sounds the Oliphant, calling Charlemagne back after it is clearly too late. He sounds the horn with all his might, and the Saracens retreat from the field, victorious by any modern standard but, to the medieval mind, leaving Roland as the last man on the field and thus conceding the fight to him. Roland then lies down and dies, having just blown his horn so hard he has given himself an aneurysm. Then, Charlemagne returns with his troops and finds Roland, unscathed by any wound but still entirely dead, facing the enemy with his sword drawn even to his last moment; they're aware they've been called back at such a late hour only to give the rear-guard a proper Christian funeral, which they do. Ganelon is placed on trial by combat; his champion's defeat proves his treason and justice is served. So end the stories of Charlemagne's greatest knights, and especially of Roland.
Much like the Iliad, this story tells of a battle that claims the lives of all the greatest warriors the nation it describes has ever known, and with the loss of Roland and the Twelve Peers, France's age of great heroes is over. Very few of the other pieces of the Matter of France can be clearly said to take place after the death of Roland; quite a few can be definitively placed before it. Nor should we expect any such sequels; after Roncesvalles, the heroes of myth are no more. And, as the Twelve Peers are men of myth, better and more just than any who live after, they cannot truly be said to match the historical people who may have inspired them. Nor should we be disappointed that their death is one worthy of legends, falling only to a force of hundreds of thousands, being carried off to Heaven in the arms of archangels, and earning a glorious victory even in their deaths. When we find historical antecedents for occurrences in the stories of the Matter of France, we are finding the things that inspired the legends, but these cannot be called the "real story" behind such events as Roland's death at Roncesvalles. The real story, to the high medieval teller, is the one about the mythical Roland, not the all-too-human Hruodland, and the fact that the story belongs to folklore and to literature rather than to the study of historical fact is unchanged by the realization that a real eighth-century battle against a ragtag group of Basques may have helped inspire the form of the legends.