In the vast majority of cases, it is not necessary to invoke such recognition. For example, in democratic countries, a government is always regarded as being legitimate when it comes to power in free elections that follow constitutional law. However, in countries with less stable governments determining legitimacy can be more difficult. For example, when a country experiences a coup, especially a coup against an elected president, other countries may wish to not recognize the new military government as legitimate, and continue to back the deposed leader, who they will continue to regard as holding office. It is assumed that if enough countries withhold recognition of a "rebel" or illegal government, that government will have no choice to step down, or fear international isolation.
In practice, this scenario rarely occurs. Thurought history most military governments have been formally recognized as legitimate by most states, even democratic countries. This is because from a strictly practial point of view, it does not make sense to ignore the de facto ruler of a country, especially when diplomatic relations with that country are important to maintain.
Some examples of governments which have not been regarded as legitimate or granted diplomatic recognition include the Taliban government of Afghanistan, which lasted 1996-2001 and was recognized by only three countries. The vast majority of countries and the UN continued to recognize the government of ousted President Burhanuddin Rabbani as being the legitimate government.