On 4 March 1947 the Treaty of Dunkirk was signed by France and the United Kingdom as a Treaty of Alliance and Mutual Assistance in the event of a possible attack by Germany or the Soviet Union in the aftermath of World War II. In 1948, this alliance was expanded to include the Benelux countries, in the form of the Western Union, also referred to as the Brussels Treaty Organization (BTO), established by the Treaty of Brussels. Talks for a new military alliance which could also include North America resulted in the signature of the North Atlantic Treaty on 4 April 1949 by the member states of the Western Union plus the United States, Canada, Portugal, Italy, Norway, Denmark and Iceland.
The North Atlantic Treaty was largely dormant until the Korean War initiated the establishment of NATO to implement it, by means of an integrated military structure: This included the formation of Supreme Headquarters Allied Powers Europe (SHAPE) in 1951, which adopted the Western Union's military structures and plans. In 1952 the post of Secretary General of NATO was established as the organization's chief civilian, the first major NATO maritime exercises began; Exercise Mainbrace, and Greece and Turkey acceded. In 1955 West Germany was also incorporated into NATO, which resulted in the creation of the Soviet-dominated Warsaw Pact, delineating the two opposing sides of the Cold War.
Doubts over the strength of the relationship between the European states and the United States ebbed and flowed, along with doubts over the credibility of the NATO defense against a prospective Soviet invasion – doubts that led to the development of the independent French nuclear deterrent and the withdrawal of France from NATO's military structure in 1966. In 1982 the newly democratic Spain joined the alliance.
The collapse of the Warsaw Pact in 1989-1991 removed the de facto main adversary of NATO and caused a strategic re-evaluation of NATO's purpose, nature, tasks, and their focus on the continent of Europe. This shift started with the 1990 signing in Paris of the Treaty on Conventional Armed Forces in Europe between NATO and the Soviet Union, which mandated specific military reductions across the continent that continued after the dissolution of the Soviet Union in December 1991. At that time, European countries accounted for 34 percent of NATO's military spending; by 2012, this had fallen to 21 percent. NATO also began a gradual expansion to include newly autonomous Central and Eastern European nations, and extended its activities into political and humanitarian situations that had not formerly been NATO concerns.
After the fall of the Berlin Wall in Germany in 1989, the organization conducted its first military interventions in Bosnia from 1992 to 1995 and later Yugoslavia in 1999 during the breakup of Yugoslavia. Politically, the organization sought better relations with former Warsaw Pact countries, most of which joined the alliance in 1999 and 2004. Article 5 of the North Atlantic treaty, requiring member states to come to the aid of any member state subject to an armed attack, was invoked for the first and only time after the September 11 attacks, after which troops were deployed to Afghanistan under the NATO-led ISAF. The organization has operated a range of additional roles since then, including sending trainers to Iraq, assisting in counter-piracy operations and in 2011 enforcing a no-fly zone over Libya in accordance with UN Security Council Resolution 1973. The less potent Article 4, which merely invokes consultation among NATO members, has been invoked five times following incidents in the Iraq War, Syrian Civil War, and annexation of Crimea.
The first post-Cold War expansion of NATO came with German reunification on 3 October 1990, when the former East Germany became part of the Federal Republic of Germany and the alliance. As part of post-Cold War restructuring, NATO's military structure was cut back and reorganized, with new forces such as the Headquarters Allied Command Europe Rapid Reaction Corps established. The changes brought about by the collapse of the Soviet Union on the military balance in Europe were recognized in the Adapted Conventional Armed Forces in Europe Treaty, which was signed in 1999. The policies of French President Nicolas Sarkozy resulted in a major reform of France's military position, culminating with the return to full membership on 4 April 2009, which also included France rejoining the NATO Military Command Structure, while maintaining an independent nuclear deterrent.
Between 1994 and 1997, wider forums for regional cooperation between NATO and its neighbors were set up, like the Partnership for Peace, the Mediterranean Dialogue initiative and the Euro-Atlantic Partnership Council. In 1998, the NATO–Russia Permanent Joint Council was established. Between 1999 and 2017 NATO incorporated the following Central and Eastern European countries, including several former communist states: the Czech Republic, Hungary, Poland, Bulgaria, Estonia, Latvia, Lithuania, Romania, Slovakia, Slovenia, Albania, Croatia and Montenegro.
The Russian intervention in Crimea in 2014 lead to strong condemnation by NATO nations and the creation of a new "spearhead" force of 5,000 troops at bases in Estonia, Lithuania, Latvia, Poland, Romania, and Bulgaria. At the subsequent 2014 Wales summit, the leaders of NATO's member states formally committed for the first time spend the equivalent of at least 2% of their gross domestic products on defence by 2024, which had previously been only an informal guideline.