The term castle can actually be quite confusing if used improperly. When I talk about Japanese castles, the term "castle" (shiro) always refers to the whole compound including the main keep, watch towers, walls, gates and moats. The main keep, is called tenshu in Japanese. It is a large multi-storey tower that the castle is centered around. It is the most heavily fortified structure and the last line of defense for the daimyo (castle lord).
When daimyo constructed castles the first and most important step was to lay out the territory and structure of the compound. In Japanese, the word territory is nawabari which means "to lay down rope" and that is literally what they did. They laid out ropes to plan the castle compound before actually constructing it. The surrounding landscape often played an important role in the planning of the castle site and aided in its defense.
Surrounding the main keep is a series of walls, moats and baileys which are invaluable defenses for any castle. These are arranged in a complicated manner to confuse enemies and make it difficult for them to breach the castle. It is understandable that the details of an opponent's castle were greatly desired before launching any attack. Between the walls, moats and other fortifications were storehouses; quarters for troops, family and vassals; as well as various other support structures. The castle itself was a small community.
There are three major types of castles: mountaintop (yamajiro), flatland-mountain (hirayamajiro) and flatland (hirajiro). Each had unique advantages and disadvantages associated with its location.
Mountaintop Castles (yamajiro)
The earlier castles were mostly built on the top of mountains and didn't have as well developed fortifications as the other two castle types. Mountaintop castles were primarily used only in a time of war, otherwise, warlords lived in a fortified home in a more convenient location. This type of castle was advantageous because it provided an excellent view of the surrounding area and was difficult to attack. Mountaintops also proved to be less susceptible to damage from earthquakes. Gifu-jo and Iwakuni-jo are prime examples of the mountaintop castle. Iwakuni-jo is shown below. In the case of both of these castles, it is currently much easier to get to them by ropeway.
Flatland-Mountain Castles (hirayamajiro)
In the Sengoku Period, castles started to be built in more convenient lowland locations. The flatland-mountain castles were built on low mountains or large hills where a plain spread out before them. This increased the efficiency of communication and eliminated many of the problems of Mountaintop castles. Unfortunately, the field of vision was decreased and the castle was more vulnerable. To make up for these disadvantages there was great development in the moats, walls, and other fortifications surrounding the castle. Himeji-jo is a good example of this type.
Flatland Castles (hirajiro)
Flatland castles were built at the end of the Sengoku period and the beginning of the Edo period. These castles were generally built in the middle of an open plain to ease communications and government. Since they had little or no natural defenses the moats and walls of these castles were built bigger and stronger than other types of castles. One disadvantage of flatland castles is that they can be susceptible to floods. The first castle of this type was Osaka-jo built by Toyotomi Hideyoshi. Nagoya-jo and Edo-jo are also good examples of this type. Shown below is Matsumoto-jo.