Many animals gain benefits from living in groups, such as a dilution in predation risk when they are closely aggregated (referred to as the ‘selfish herd’). Game theory has been used to predict many properties of groups (such as the expected group size), but little is known about the proximate mechanisms by which animals achieve these predicted properties. We explore a possible proximate mechanism using a spatially explicit, individual–based model, where individuals can choose to rest or forage on the basis of a rule–of–thumb that is dependent upon both their energetic reserves and the presence and actions of neighbours. The resulting behaviour and energetic reserves of individuals, and the resulting group sizes, are shown to be affected both by the ability of the forager to detect conspecifics and areas of the environment suitable for foraging, and by the distribution of energy in the environment. The model also demonstrates that if animals are able to choose (based upon their energetic reserves) between selecting the best foraging sites available and moving towards their neighbours for safety, then this also has significant effects upon individuals and group sizes. The implications of the proposed rule–of–thumb are discussed.