Sex pheromones facilitate reproduction by attracting potential mates and altering their behavior and physiology. In C. elegans, males and hermaphrodites secrete similar blends of pheromone molecules, two of which are present in different relative concentrations: ascr#3, which is more abundant in hermaphrodites, and ascr#10, which is more abundant in males. It is not currently understood how this compositional difference results in sex-specific effects, for example, the slower aging of the hermaphrodite germline in the presence of physiologically relevant concentrations of male pheromones. Here we report three key elements of the mechanism responsible for this phenomenon. First, ascr#3 counters the activity of ascr#10. This antagonism decreases the magnitude and the sensitivity of the hermaphrodite response to the male pheromone, restricting it to situations in which the presence of a male could be inferred with high confidence. Second, hermaphrodites recognize pheromone as male if the concentration of ascr#10 is higher than that of ascr#3. Third, the response to ascr#10 requires TRPV channel function in the ADL neurons and the daf-7 signaling from the ASI neurons, whereas the response to ascr#3 relies on cyclic guanosine monophosphate (cGMP)-gated channels and activity of the ASJ, AWB, and AWC neurons. These results argue that the counteracting activities of distinct neuronal circuits determine the sexual identity of the pheromone. The parallels between this mechanism and other signaling systems suggest that diverse organisms may perform particular neuronal computations using similar general principles.