(photo: CGP Grey)
Embassies are essentially the office of a country/government that resides in a foreign country.
For example, the US Embassy in Germany is an extention of the US Govt in Germany. Likewise, the German Embassy in the US is an extension of the German govt.
The highest ranking official in an Embassy is an Ambassador.
Their purpose is fairly wide ranging, but here’s a few simple examples:
Ambassadors are diplomats who are the President’s eyes, ears, and mouth on the ground in the country he/she is located in. The Ambassador works with the local national government on behalf of POTUS. Embassies are usually located in the capital city, while other cities may have smaller offices known as Consulates.
And while the Embassy is located within the borders of a foreign country, the Embassy grounds themselves are treated as a “border” that may not be crossed without permission. Doing so could be considered an act of aggression.
The Embassy can act as a save haven of sorts for US citizens in foreign countries. If Germany was attacked by Russia, US citizens in Germany could seek refuge in the Embassy, and the Embassy would also assist in getting them evacuated from the country. A less extreme example would be that a US citizen traveling abroad lost his/her wallet and needs assistance with getting a new ID, credit cards, etc.
Embassies also serve other purposes, like providing screening for foreign nationals wishing to enter the US.