It always pains me to disagree with a poster, but I'm a professional research editor and I just can't help myself. The first recorded use of "number two" as a euphemism for defecation was in 1902, some 60 years after indoor plumbing had become the norm in most U.S. schools. The outhouse explanation is actually an urban legend. :-(
Please don't be pained on my account, because you've provided me with an interesting amateur research project now. ;-) I usually confine my research to fiction-writing projects these days, but I'm enough of a "geek" to enjoy a good hunt.
I will gladly accept the word of a professional researcher that the first
recorded use of the term was in 1902. And I'm willing to entertain the possibility that school houses across the Northeast U.S. and in American metropolitan areas all did indeed have indoor plumbing in the 1840s, but I'm interested in the rest of the country in that era, given that America's populace was still largely agrarian then. I know from personal experience with my grandparents' (seasonally freezing or sweltering) outhouse in the 1960s that indoor plumbing reached rural areas long after that. The last of my "deep-hills" (meaning geographically isolated by low mountains) relatives acquired indoor plumbing in the late 1970s.
I was careful to attribute the "source" of the information I had been given to "older people" because I was aware I did not have academically sound sources for the subject. The people in question, though, are my parents (born 1929 and 1939) and grandparents (born early 1900s), who had all attended one-room school houses in the Ozark mountains (a region in America's upper South), and who had all used the one- or two-finger signals themselves. In the 1950s, when my mother first attended an actual high school in an oh-so-small "town," it was her first regular access to indoor plumbing. They all were under the impression that the origins of the expression are as I relayed above, though confusing correlation for causation is an easy enough mistake for people far more educated than those generations of my family were. In any case, teachers used the information gleaned to estimate how long to wait to check on an "excused" child. So whether the hand gestures gave way to a descriptive verbalization, or whether the two are separate phenomena is an interesting question.
With Polish and Danish posters mentioning that the same expression is found in their own languages, it seems quite possible that the expression (and/or possibly original or related finger signals) is much older than this country. Another possibility is that some shared cultural event brought the expression (and/or finger signals?) to multiple countries in more recent times. Given that no one here seems aware of such an event, that seems less likely to me, although I'm interested in what the record will show. Please, please share whatever else you find on this topic. I'm also curious as to whether the elderly in Poland and Denmark remember using or have heard of others using the one-finger of two-finger signals to be allowed to use the "restroom" in non-urban schools.