Beijing as a national capital grew out of the Yuan (Mongol) capital Dadu or Khanbaliq. The Ming moved their capital there from Nanjing in 1421.
The walls in the photographs below, built under the Ming, are those of the Inner City. Under the Manchu or Qing Dynasty rulers (1644-1912), it came to be called the Tartar City, in the loose sense of Tartar, because only Manchus were allowed to live there.
The Han Chinese, whose businesses depended on the imperial households, lived in the Outer City, which had its own wall.
Historical names of Beijing (Wikipedia).
The Inner and Outer walls were damaged during the Boxer Rebellion, punctured in various places after 1911 and almost entirely dismantled by the Communists.
Walls of the Tartar City via visualisingchina.net: