I like this as an introduction, which sets some good rules of thumb, but there are some excellent exceptions to these rules that we can get into. For example, in mammals (even humans), the part of the Y chromosome that is most responsible for turning on the male-determining pathway doesn’t always function as it should, resulting in individuals with an X and a Y chromosome who have female physical characteristics (for more see Ed Yong’s article about Chen et al.’s 2013 paper).