Just like cis kids! Some don't know or don't care, but many are aware of what their gender is as soon as they're aware of what gender is in general.
The biggest and most reliable sign of if a kid is trans, is whether they claim they are the opposite sex, and insist on it.
Because they are becoming aware of social differences between boys and girls, and know they haven't been put on the correct side. Just like when a cis kid knows when they are mistaken for the wrong gender, and corrects whoever made the mistake.
And it is not because of genitals, because some parents don't even teach their children that boys and girls have different genitals, yet their children can still know their own gender—and tell their parents if their parents call them the wrong one.
How people develop from kids into adults is strange and fascinating, especially the brain. But it seems that development of gender—however that happens—happens very early. And from young child to adult, people are only more aware of their gender if they pay attention to it.