Drosophila determines its sex by "counting" X chromosomes. We show that premature expression of the pair-rule segmentation gene hairy interferes with this process, resulting in female-specific lethality by inhibiting initiation of the master control gene Sex-lethal (Sxl). The female-specific lethality can be suppressed by a constitutive Sxl allele or by extra copies of X-linked "counting elements." These results are best explained by competition between hairy and other helix-loop-helix transcription factors that act in chromosome counting. We have confirmed this model by showing that misexpression of the achaete-scute T4 gene induces ectopic Sxl expression and male-specific lethality, confirming that achaete-scute T4 is the sisterless-b counting element. We propose that X chromosomes are counted through heterodimers of helix-loop-helix transcription factors that act synergistically to initiate Sxl expression.