Hanover is a borough in York County, Pennsylvania, United States, 19 mi southwest of York and 54 mi north-northwest of Baltimore, Maryland and is 5 mi north of the Mason-Dixon line. The town is situated in a productive agricultural region. The population was 16,429 at the 2020 census. The borough is served by the 717 area code and the ZIP Codes of 17331–34. Hanover is named after the German city of Hannover.