It's pretty simple. Assuming a relatively normal childhood without history of sexual experiences before puberty, at around the age of 12 or thirteen, when the other boys start noticing girls, the gay kid will start noticing boys. Sexual attraction and arousal are powerful forces in teenagers and gay males know pretty quickly what they are attracted to but are forced to repress those feelings by societal conventions.
Ask them. Ask them. A corollary would be how did you know in high school that you are heterosexual? I bet the answer is the same.