Two-by-two tables commonly arise in comparative trials and cross-sectional studies. In medical studies, two-by-two tables may have a small sample size due to the rarity of a condition, or to limited resources. Current recommendations on the appropriate statistical test mostly specify the chi-squared test for tables where the minimum expected number is at least 5 (following Fisher and Cochran), and otherwise the Fisher–Irwin test; but there is disagreement on which versions of the chi-squared and Fisher–Irwin tests should be used. A further uncertainty is that, according to Cochran, the number 5 was chosen arbitrarily. Computer-intensive techniques were used in this study to compare seven two-sided tests of two-by-two tables in terms of their Type I errors. The tests were K. Pearson's and Yates's chi-squared tests and the ‘N−1’ chi-squared test (first proposed by E. Pearson), together with four versions of the Fisher–Irwin test (including two mid-P versions). The optimum test policy was found to be analysis by the ‘N−1’ chi-squared test when the minimum expected number is at least 1, and otherwise, by the Fisher–Irwin test by Irwin's rule (taking the total probability of tables in either tail that are as likely as, or less likely than the one observed). This policy was found to have increased power compared to Cochran's recommendations. Copyright © 2007 John Wiley & Sons, Ltd.