There is no limit to the number of red cards that a referee can give, though the game would be stopped as soon as there are less than 7 players of a team remaining legally on the pitch.
As of Law 3 in the FIFA Law Book, there cannot be less than 7 players of a team, on the field during play. In effect, a maximum of 4 on-field players of the same team can be dismissed. Once 5 on-field players (substitutes do not count) of the same team are red carded, the match ends.
If the referee has red-carded 4 players and all 7 substitutes of each team (22 players in total), the game can still continue, provided there are no further red cards to players of either side.
The law (for continuation of the game) however, states only the on-field players. There is no limit to the number of red cards that can be shown to the substitutes on the bench, the manager and the coaching staff. Also, red cards can be handed to the on-field players/substitutes/coaching staff after the game has ended based on the referee reports and video analysis (wherever applicable).
The record for the most red-cards handed out in a single match is during a fifth tier Argentinian league game between Claypole and Victoriano Arenas, where 36 red cards were shown.