The history of the United States Coast Guard goes back to the United States Revenue Cutter Service, which was founded on 4 August 1790 as part of the Department of the Treasury.
The Revenue Cutter Service and the United States Life-Saving Service were merged to become the Coast Guard per 14 U.S.C. § 1 which states: "The Coast Guard as established January 28, 1915, shall be a military service and a branch of the armed forces of the United States at all times."
In 1939, the United States Lighthouse Service was merged into the Coast Guard. The Coast Guard itself was moved to the Department of Transportation in 1967, and on 25 February 2003 it became part of the Department of Homeland Security.
However, under 14 U.S.C. § 3 as amended by section 211 of the Coast Guard and Maritime Transportation Act of 2006, upon the declaration of war and when Congress so directs in the declaration, or when the President directs, the Coast Guard operates as a service in the Department of the Navy.