The short answer
A duke has higher status than an earl. In the British peerage the order from the top is duke, marquess, earl, viscount and baron, so a duke ranks two places above an earl, with the marquess between them. The full order is set out in the list of British titles in order.
Where each sits in the peerage
Dukes are the highest rank of the peerage below the royal family. Earls come third. A duke’s wife is a duchess, and an earl’s wife is a countess. Sons and daughters of peers use courtesy styles that depend on the father’s rank, so the children of a duke generally carry higher styles than the children of an earl. The sequence is described step by step in what is the order of the English nobility.
Origins of the two titles
Earl is the older title, with roots in the period before the Norman Conquest, when an earl was a powerful regional lord. Duke was introduced into England later, in the 14th century, and was originally given to the king’s close male relatives. Because the title was so closely tied to the Crown, it ended up ranking above the older earldoms.
An earl can still be older or richer
Rank is not the same as age, wealth or influence. Some earldoms are much older than most dukedoms, and an individual earl can own more land or have more public standing than a duke. Status, in the sense of formal precedence, is set by rank, and among peers of the same rank, it generally goes by the age of the creation.
How to address each
A duke or duchess is formally addressed as “Your Grace.” An earl is usually addressed as “Lord” followed by the title, such as “Lord Derby” in ordinary speech, and a countess as “Lady.” The wider question of how medieval ranks compared is explored in medieval titles in order.