What is the difference between synecdoche and metonymy?

Synecdoche and metonymy are both types of tropes used in rhetoric. Although both involve replacing one word with another, they are not the same thing.

While synecdoche involves replacing a specific part of something with the whole, metonymy involves replacing a word or phrase with a related one. For example, “stars and stripes” is a synecdoche for the American flag because these are part of the flag. On the other hand, “the crown” is a metonymy for the monarchy.