It is interesting to see how nobility titles in Western Europe have changed their meaning along History. Some of them dating back as long as the Roman Empire, during the Middle Ages acquired their meaning related to land ownership. Currently, titles are merely honorific.
The title of duke is traditionally the one of highest rank. he word comes from Latin "dux", meaning "military commander", and was employed by both Romans and Germans to refer their warrior leaders. In the Roman army, a dux was a general in charge of two or more legions, who normally managed the government of a province (both civil and military). In the Roman Empire, the powers of the dux were limited to strictly military, depending on the governor (normally a "comes") to make use of them. In Byzantium, "dux" became viceroys at the head of every administrative and military service.
During the Middle Ages, dukes became the closest nobility title to the king, and their function was essentially military, with a territorial aspect though, as they ruled in a set of countships. Of course, there exist variations in the meaning of dukes in every kingdom. Frankish dukes were the nobles of highest rank, from where province governors came out, although they also appear leading military expeditions away from their duchies. Later, Charlemagne restructured administratively the kingdom, multiplying the number of counts and reducing that of dukes, limiting it to the nobles closest to him. In Spain and Italy, Visigoth and Lombard dukes, respectively, were the greatest land owners and, together with bishops, they elected the king among them. Although the were nominally loyal to the king, the concept of monarchy was new for them and dukes acted independently from royal authority, specially in central and south Italy, where the duke of Spoleto and the duke of Benevento were sovereigns de facto. Also in Germany, duchies were independent kingdoms inside the Holy Empire, and in Italy, "doges" were the heads of state in some of the Republics in the peninsula (Genoa, Venice). In modern times, variants from this title ("Conde-duque" in Spain, Archduke in Austria) to refer the head of state.
Etimologically from the Latin "comes", which means companion or delegate of the emperor during the Roman Empire. Its origin is in the people surrounding Augustus ("amici Augusti"), normally selected from senators, who when travelling became "comites Augusti", being their role just that of personal advisors. They disappeared with Alexander Severus and created again under Constantine, when they designated the most loyal to the emperor, being a hierarchy over regular officials. They had a political and administrative role, with military functions specially when defending borders.
During the Germanic kings, counts were designated by a dux or the king. The title of count was indistintively given to every official around him, one of which, the count palatine ("comes palatii"), was in charge of rendering justice inside the palace. Some arms companions of Frankish merovingian princes received the title for city administration. At these times they start to have fiscal, military and judiciary functions. Military power only never depended on a moving army, but settled on a territory (countship). In the countship, he rivalised mainly with the bishop (in his corresponding diocese) for the use of power. Under Charlemagne, counts were given a specific mission (military or administrative) with temporal character, and never hereditary. It is only after the 9th century that counts start to form a land owner class, usurpating royal rights over their countship land. The title was also often given by the monarch as gratitude for a special service, without necessary being accompanied of a feudal territory. In England, there exists the equivalent "Earl", term originated in Scandinavia.
The original title comes from German "markgraf" (literally "count of the mark"). During the High Middle Ages, and specially in the Carolingian Empire, it was a count who administered a border territory (mark). In order to allow him a quick reaction to potential attacks, special military powers were given to him to raise up the army without the express permission of the king. This authority has later conferred it a higher rank than the count, but lower than the duke, as the latter has a military and judiciary power over several countships. After the collapse of the Carolingian Empire, the marquis title fell into disuse, except certain counts who proclaimed themselves marquis to acquire greater importance (that is the case of the count of Barcelona, who justified this action for being situated in the border with hispanic Muslim kingdoms). In modern times it resurected as an honorific title.
Etimologically coming from a mixture between the Frankish word "baro" ("warrior") and the Angle "beorn" ("noble"). Since the Middle Ages, it refered those who had obtained privileges directly from the king because of a military service, situated just over the title of knight. Acording to the country, the meaning was different: In France, for being baron, it was required to possess at least two castles. In Spain barons were the rich and magnates who participated in political sessions. In the Holy Empire, every family in the low nobility were granted the title of baron (distinguished with the prefix "von"). The English king Henry II made a distintion between greater and lesser barons. Since the 16th century, baronship looses its relation with land ownership, becoming a nominal title.