Ansbach (; German pronunciation) is a city in the German state of Bavaria. It is the capital of the administrative region of Middle Franconia. Ansbach is 25 miles (40 km) southwest of Nuremberg and 90 miles (140 km) north of Munich, on the Fränkische Rezat (Rezat River), a tributary of the Main river. In 2004, its population was 40,723. Developed in the 8th century as a Benedictine monastery, it became the seat of the Hohenzollern family in 1331. In 1460, the Margraves of Brandenburg-Ansbach lived here. The city has a castle known as Margrafen–Schloss, built between 1704–1738. It was not badly damaged during the World Wars and hence retains its original historical baroque sheen. Ansbach is now home to a US military base and to the Ansbach University of Applied Sciences. The city has connections via autobahn A6 and highways B13 and B14. Ansbach station is on the Nürnberg–Crailsheim and Treuchtlingen–Würzburg railways and is the terminus of line S4 of the Nuremberg S-Bahn.