Dey’s formula can be used to count the subgroups of finitely generated groups and to establish congruence properties of subgroup counting functions. We develop an algebraic technique based on this formula for counting the subgroups of given index in Hecke groups, and show how to streamline it for efficient computation modulo \(2\).