Species differ enormously in their territorial systems. Some species defend only small areas surrounded by undefended space, while others defend large contiguous territories. Using an optimization approach, we show that this variation can be explained from the density of two types of resources: divisible and nondivisible. We assume that benefits of territories are monotonously related to the defended amount of divisible resources (hereafter called food). In contrast, no benefits are obtained without a nondivisible resource (hereafter called nest site) in the territory, while more than one nest site does not further increase the benefits. The optimal territory size depends on the relative abundance of these resources. With a low density of n...