There are no definitive guidelines to the distinction between “at school” and “in school” because the terms are used in a different way in different English dialects (there are regional differences even among British and American dialects). The general trends are as follows:
For the vast majority of Americans, “being in school” means “being a student”, and “being at school” means “currently being gone to school”, just like we would say that we are “at work”:
He is still at school. = He still hasn’t come back from school today.
Note, however, that Americans often use “school” in this context to refer to any kind of education (not just primary and secondary school), so someone studying in college could also be referred to as being “in school”. The British, on the other hand, would likely say “at university”, and someone who is “in school” (in British English) has not started their studies at a university yet.
“Being in school” means in principle the same as in American English, i.e. “being a pupil”, but it is more common to use “at school” in this context, which can mean either “being a student” or “currently being gone to school”:
He is still at school. = Either he is still a pupil or he still hasn’t come back from school.
Having considered all that has been said, I believe it is advisable for an English learner to follow the “American” convention, i.e. to use “in school” for “being a student” and “at school” for physical presence at school. This will be universally understood in the US as well as in the UK, while the British convention might raise a few eyebrows in the US.
However, it is better to avoid the American way of referring to college students as being “in school” (there is nothing wrong with saying they are “in college” or “at university”), as this could lead to a misunderstanding among speakers of British English.