Carrying out a chi-square test

The chi-square statistic adds up each cell's squared gap between observed and expected counts over the expected count, and large values, far out in a chi-square distribution with (rows - 1)(columns - 1) degrees of freedom, are evidence against the null.

From AP Statistics.