Politics was much more personal in the Middle Ages. Rather than stationing missiles along the border to make sure a peace treaty stayed enforced, warring states and individuals would demand hostages. A hostage was surety for good behavior, and might be offered for the short term (such as while someone was being given a safe-conduct across a territory) or the long term (such as as assuring a one-time rebel would not rebel again in the future).
Hostages could be any number of different people, but the highest value hostages were the enemy's sons. Even if someone were not explicitly called a hostage, the status would be clear.
For example, King Charles the Bald (Charlemagne's grandson) had a number of dukes and counts try to rebel against him. Generally these rebellions were pacified without too many people getting killed—unlike modern warfare (or the board game Risk), the purpose of fighting was not to kill as many guys as possible but rather to get the other side to pay attention.
Charles, "to show there were no hard feelings," would invite the penitent rebels to send their sons "to be brought up at court." There the boys would indeed be treated well, but everyone knew they were hostages for their fathers' good behavior. They could, at least theoretically, be put to death very quickly if any new rebellions broke out; ruthlessness, after all, is the other side of trying to settle things without too many deaths. But in practice threatened execution of hostages happened far more than actual execution. Especially if a rebel's sons were at court, he would generally change his mind about rebelling.
For the hostage boys, besides being summarily killed, the other danger (at least as their fathers saw it) was to become too close with those who were holding them hostage, what today is called Stockholm Syndrome. And why shouldn't they become close to their captors? They saw "Uncle" Charles (or whoever) almost every day; he encouraged them and educated them and made them presents and took them hunting and let them flirt with the ladies of court. When their fathers expired of natural causes, they would go back and take up their fathers' rule as loyal allies to the crown.
During the early Middle Ages, hostages were almost always male. But starting in the eleventh century, girls and women started appearing as hostages. Here Stockholm Syndrome really was an issue, for young women might well end up marrying someone at the court where they were hostage. Or, like the boys, they could be put to death, rather nastily if the negotiations that had brought them there totally broke down.
In the late Middle Ages, during the Hundred Years' War, the French king Jean II (1350-1364) was captured in battle by the English in 1356 and held for ransom. He was in essence a hostage, taken to England and kept there in very pleasant circumstances while the French tried to raise the very large ransom demanded.
When by 1360 it became clear that the money raising was going too slowly, he offered to go back to France and help out, and proposed his second son (Louis) as a hostage for his good faith efforts. Raising the money was a complete pain, however, as France was wracked with dissent and poverty and had apparently just lost the war. (They eventually won, due to Joan of Arc, but that's a different story.)
After three years of trying unsuccessfully to get the cash together, Jean was shocked to learn that his son had escaped from the English. Declaring that "good faith and honor" demanded it, he immediately sailed to England to become a hostage again himself, where he wouldn't have to worry about ruling, but follow the life of leisure he'd enjoyed earlier. He died in England, and the ransom never did get paid. He is known as "Jean the Good."