Much of the system was built by two private companies, the Interborough Rapid Transit Company (IRT) and the Brooklyn Rapid Transit Company (BRT, later Brooklyn–Manhattan Transit Corporation, BMT). The first subway line opened in 1904, but there had been elevated rapid transit lines since the 1870s, and those lines were often integrated into the growing subway network. The city was closely involved with these private ventures: all lines built for the IRT and most BMT lines built after 1913 were built by the city (as a sort of subterranean street) and leased to the private companies.
The city-owned Independent Subway System (IND) opened its first line in 1932 and in 1940, the two private systems were bought by the city. The New York City Transit Authority (NYCTA) was created in 1953 to take over all transit operations from the city, and that was placed under control of the state-level Metropolitan Transportation Authority in 1968.
A number of railfan websites such as nycsubway.org provide extensive info on subway history, as do books such as Clifton Hood’s 722 Miles.
ETA: most grateful to be gilded. Trying to avoid being gelded.