The economically optimal sample size in a food safety test balances the marginal costs and marginal benefits of increasing the sample size. We provide a method for selecting the sample size when testing beef trim for Escherichia coli O157:H7 that equates the averted costs of recalls and health damages from contaminated meats sold to consumers with the increased costs of testing while allowing for uncertainty about the underlying prevalence rates of contamination. Using simulations, we show that, in most cases, the optimal sample size is larger than the current sample size of 60 and, in some cases, it exceeds 120. Moreover, lots with a lower prevalence rate have a higher expected damage because contamination is more difficult to detect. Our simulations indicate that these lots have a higher optimal sampling rate.