What this answers
This test answers "are these two categorical variables associated, or does the data look consistent with them being independent?" Given a table of observed counts (for example, treatment group by outcome category), it compares what you actually observed against what you would expect if the two variables had no relationship at all.
How it is calculated
For each cell in the table, an expected count is computed from that cell's row total times its column total, divided by the overall total, the count you would expect under independence. The chi-square statistic sums, across every cell, the squared difference between observed and expected counts divided by the expected count. Larger differences from independence produce a larger statistic. Degrees of freedom equal the number of rows minus 1 times the number of columns minus 1, and the p-value is the probability of a chi-square statistic at least this large under genuine independence.
Worked example
For the table [[10, 20], [20, 10]]: row totals are 30 and 30, column totals are 30 and 30, and the overall total is 60, so every cell has an expected count of 15. The chi-square statistic works out to about 6.667 on 1 degree of freedom, which is significant at the .05 level. Cramer's V, a magnitude measure bounded between 0 and 1, comes out to about 0.333 here, a moderate association given this table's size.
Assumption audit
What this result does not mean
A significant chi-square result means the data provide evidence against independence at your chosen threshold, not that one variable causes the other. Association in a contingency table can arise from a shared underlying cause, from how categories were defined, or from the specific sample collected, not only from a direct causal link between the two variables you tested.
Limitations
This test only detects association, and Cramer's V only quantifies its strength; neither identifies which specific cells drive the result. Inspecting the observed-versus-expected counts directly, cell by cell, is often needed to explain what an overall significant result actually reflects.