The evolution of altruism is a fundamental and enduring puzzle in biology. In a seminal paper Hamilton showed that altruism can be selected for when rb − c>0, where c is the fitness cost to the altruist, b is the fitness benefit to the beneficiary, and r is their genetic relatedness. While many studies have provided qualitative support for Hamilton's rule, quantitative tests have not yet been possible due to the difficulty of quantifying the costs and benefits of helping acts. Here we use a simulated system of foraging robots to experimentally manipulate the costs and benefits of helping and determine the conditions under which altruism evolves. By conducting experimental evolution over hundreds of generations of selection in populations with different c/b ratios, we show that Hamilton's rule always accurately predicts the minimum relatedness necessary for altruism to evolve. This high accuracy is remarkable given the presence of pleiotropic and epistatic effects as well as mutations with strong effects on behavior and fitness (effects not directly taken into account in Hamilton's original 1964 rule). In addition to providing the first quantitative test of Hamilton's rule in a system with a complex mapping between genotype and phenotype, these experiments demonstrate the wide applicability of kin selection theory.