The main difference between a duke and an earl is that a duke is of a higher rank than an earl. The duke is ranked third in the royal hierarchy, under the prince and ruling monarch, whereas an earl is generally ranked sixth.
A duke is the most senior noble and is generally not a member of the royal family. The word duke comes from the Latin term dux which means leader or commander. Traditionally, dukes were appointed by the king as leader of a specific territory, acting as a delegate to uphold the king's law. The title of duke is hereditary.
The terms earl and count are used interchangeably and stand for the same noble title. An earl is a member of intermediate nobility. In both the Western and Eastern Roman Empires, this title referred to a military commander in charge of a large number of people. During the Middle Ages and after, the title and duties associated with it became more vague. In Anglo-Saxon England, earls acted as landlords, collected taxes and exercised judicial power over the villages under their control. The English Monarchy created the earl system to preserve the royal hierarchy while still being able to enforce law. Generally, earls were appointed by the king, though the title was passed to an heir with the king's approval. Earls in modern times are a more ambiguous member of the nobility that often acts an advisior of sorts to the current monarch.