The Central Intelligence Agency was formed in 1947 to be the central spy agency for the United States. In previous years, there had been many different intelligence agencies. For example, the Army would have their intelligence agency and the State Department would have theirs. These agencies did not really talk to one another.
In 1947, the Central Intelligence Agency was formed to make sure that intelligence would be gathered and shared. It was supposed to make sure that there would not be any further lapses in intelligence like the one that allowed the Japanese to attack Pearl Harbor without anyone realizing it was about to happen.
Two years later the CIA expanded in power with the Central Intelligence Agency Act of 1949. This act permitted the agency to use methods that would otherwise limit the organization from receiving federal funding. In other words, the CIA was granted special powers and its veil of secrecy, as it was exempt from disclosing information like its employees' names and salaries. This act was challenged in 1972 with the court case United States v. Richardson but was ultimately upheld.