In 1266, the English passed a law regulating the weight and price of beer and bread sold in the marketplace.
Bakers depended on middlemen to sell their excess, especially during a good harvest year, but the new law forbade them to offer a discount or a wholesale price.
They found a way to skirt the law by adding one extra loaf to each dozen.
This thirteenth loaf provided the profit for the middlemen.
The practice of adding the thirteenth loaf is older than the phrase.
The expression “a baker’s dozen” dates from only 1599.