The 21-card trick is a way of dealing cards in order to predict the card selected by a volunteer. We give a mathematical explanation of why the well-known 21-card trick works using a simple linear discrete function. The function has a stable fixed point which corresponds to the position where the selected card reaches at the end of the trick. We then generalize the 21(7 × 3)-card trick to a p × q -card trick where p and q are odd integers greater than or equal to three, determine the fixed point and prove that it is also stable.