Ueda Castle (上田城, Ueda-jō) is a Japanese castle located in Ueda, northern Nagano Prefecture, Japan. At the end of the Edo period, Ueda Castle was home to a cadet branch of the Matsudaira clan, daimyō of Ueda Domain, but the castle is better known for its association with the Sengoku period Sanada clan. It was also called Amagafuji-jō or Matsuo-jō. The castle was designated a National Historic Site of Japan in 1934.
Ueda Castle is located on a hill overlooking a branch of the Chikuma River at the northeast edge of the Nagano plain, which forms part of its southern defences and acts as a moat.
The Central Bailey (Hon-Maru)  originally had seven two-story yagura, but no tenshu and was protected by a moat as well as stone ramparts. The Central Bailey is also surrounded by a Second Bailey (Ni-no-Maru) , also with moats and earthen ramparts. The adjacent Third Bailey (San-no-maru) , had additional yagura, of which only the foundation bases remain, and contained the main residence of the daimyō [R] (which was also protected by a moat), gardens [G] and work area [A], and the main gate (Ōtemon) of the castle [H]. Most of the area of the former Third Bailey is now occupied by the Ueda High School.
During the Sengoku period, the area around Ueda was under the control of the Sanada clan, a minor local warlord in the service of the Takeda clan. After the fall of the Takeda clan to the combined forces of Oda Nobunaga and Tokugawa Ieyasu, the Sanada switched side with bewildering rapidity between the Uesugi clan, the Hōjō clan, Oda Nobunaga and Toyotomi Hideyoshi in an effort to preserve their territory and independence. The construction of the castle began in 1583 by Tokugawa Ieyasu's order. Two years later, Sanada Masayuki moved their main bastion from Sanada-shi Yakata to Ueda Castle. In the same year, the castle was attacked by Tokugawa Ieyasu but the greatly outnumbered Sanada defeated the forces of Tokugawa Ieyasu in the Battle at Kami River, which greatly enhanced Sanada Masayuki’s reputation.However, under Toyotomi Hideyoshi, the Sanada were forced to submit fealty to Tokugawa Ieyasu and Sanada Masayuki's first son, Sanada Nobuyuki, was married to Komatsuhime, an adopted daughter of Ieyasu; while his second son, Sanada Yukimura (Nobushige), was married to Chikurin-in, an adopted daughter of Hideyoshi. After the death of Hideyoshi, the Tokugawa ordered the Sanada to participate in their invasion of Aizu against the Uesugi clan. Sanada Nobuyuki chose to remain on the Tokugawa side, while Sanada Masayuki and his younger son, Sanada Yukimura chose to join the Toyotomi armies under Ishida Mitsunari against the Tokugawa. This led to the Siege of Ueda in 1600, a side battle to the Battle of Sekigahara. The army of Tokugawa Hidetada, while on their way to Sekigahara was ordered to reduce Ueda Castle along the away. Again, the greatly outnumbered Sanada forces inflicted severe casualties on the Tokugawa and delayed Hidetada so long that he was forced to break off the siege and his forces thus arrived at Sekigahara too late to make a contribution to the battle.After the Battle of Sekigahara and the establishment of the Tokugawa shogunate, Sanada Masayuki submitted to Tokugawa Ieyasu, but was dispossessed and Ueda Castle was partially demolished. Sanada Nobuyuki was made daimyō of Ueda Domain, and returned to build a residence in the former San-no-maru area. He was transferred to nearby Matsushiro Domain in 1622, and replaced by the Sengoku clan, who rebuilt parts of the Main Bailey and Second Bailey from 1628, but the tenshu was not restored. The Sengoku were in turn replaced by a branch of the Matsudaira clan in 1706, who remained in control of the castle until the end of the Edo period.Following the Meiji restoration and the abolition of the han system, the castle was dismantled, leaving only the stone ramparts and one yagura. The site was made into a public park, with two Shinto shrines (one dedicated to the Sanada clan, and the other to the war dead), and a local history museum. In 1949, two yagura were reconstructed, and in the 1990s one of the gates was rebuilt.Ueda Castle was listed as one of the 100 Fine Castles of Japan by the Japan Castle Foundation in 2006. The castle is a ten-minute walk from Ueda Station on the Nagano Shinkansen.