Cooperation among group members, coworkers and community members can provide benefits for all involved parties. However, groups of all kinds are plagued by free riders, or individuals who take advantage of cooperative group members by benefiting from being a part of the group without contributing, resulting in a social dilemma or 'tragedy of the commons.' This phenomenon is not unique to humans; free riders can be identified in organisms as simple as bacteria. This has lead to the puzzling question of how cooperation is maintained in social groups of humans and other animals, given higher payoffs for free riding than for cooperation. In order to address this question, I simulate individuals who use a simple Walk Away rule to leave uncooperative partners or groups, and show that cooperation is favored under a variety of parameter values when agents can use this rule. When agents use the Walk Away rule, more cooperative partnerships and groups are more stable than less cooperative ones. This promotes assortment, or the preferential interaction of cooperators with one another, which favors the evolution of cooperation. It is shown that in dyadic partnerships Walk Away can outperform the well-known Tit-for-Tat strategy. In group-wise interactions, the Walk Away rule generates large number of relatively small groups and differential group stability based on average cooperativeness. These features maintain selection for cooperation by generating population structures that promote group selection. The simple Walk Away rule does not require complex individual level abilities such as long-term memory, recognition of group members or punishment, suggesting that complex cognitive abilities are not necessary for cooperation to be promoted.