A peg buys price stability, which is useful for an economy that imports heavily or invoices its main export in dollars, and it imports the monetary policy of the anchor currency along with it. The cost is the loss of an independent policy rate: defending the rate has to come first.
Pegs come in degrees. A hard peg at a single rate, a band such as Hong Kong's linked exchange rate system with its 7.75 to 7.85 convertibility undertaking against the dollar, a crawling-peg that moves on a schedule, or the full institutional version in a currency-board.
Pegs fail when the market can borrow the currency more cheaply than the authorities can defend it, or when defending it becomes politically unaffordable. black-wednesday and asian-financial-crisis-1997 are the standard examples, and the modern version is described in swiss-franc-unpeg.
Example: with a band of 7.75 to 7.85, a trader buying USD/HKD at 7.7500 has a known floor and a ceiling 1.3% above. The carry earned or paid while waiting usually decides whether that is worth doing.
Related: currency-board, crawling-peg, managed-float, devaluation