A person’s sex is usually determined entirely by the chromosomes you end up with:
The common pathway of sexual differentiation, where a productive human female has an XX chromosome pair, and a productive male has an XY pair, is relevant to the development of intersexed conditions.
During fertilization, the sperm adds either an X (female) or a Y (male) chromosome to the X in the ovum. This determines the genetic sex of the embryo. During the first weeks of development, genetic male and female fetuses are “anatomically indistinguishable,” with primitive gonads beginning to develop during approximately the sixth week of gestation. The gonads, in a “bipotential state,” may develop into either testes (the male gonads) or ovaries (the female gonads), depending on the consequent events. Through the seventh week, female and male fetuses appear identical.
At around eight weeks of gestation, the gonads of an XY embryo differentiate into functional testes, secreting testosterone. Ovarian differentiation, for XX embryos, does not occur until approximately Week 12 of gestation. In normal female differentiation, the Müllerian duct system develops into the uterus, Fallopian tubes, and inner third of the vagina. In males, the Müllerian duct-inhibiting hormone MIH causes this duct system to regress. Next, androgens cause the development of the Wolffian duct system, which develops into the vas deferens, seminal vesicles, and ejaculatory ducts. By birth, the typical fetus has been completely “sexed” male or female, the hormones and genital development remaining consistent with the genetic sex.
This process screws up sometimes:
The final body appearance does not always correspond with what is dictated by the genes. In other words, there is sometimes an incongruity between genotypic (chromosomal) and phenotypic sex. Citing medical research regarding other factors that influence sexual differentiation, the Intersex Society of North America challenges the XY sex-determination system‘s assumption that chromosomal sex is the determining factor of a person’s “true” biological sex.
example 1: congenital adrenal hyperplasia
The most common cause of sexual ambiguity is congenital adrenal hyperplasia (CAH), an endocrine disorder in which the adrenal glands produce abnormally high levels of virilizing hormones.
In people without a Y chromosome (i.e., XX), this can range from partial masculation that produces a large clitoris, to virilisation and male appearance. The latter applies in particular to Congenital adrenal hyperplasia due to 21-hydroxylase deficiency, which is the most common form of CAH.
Individuals born with XX chromosomes affected by 17α-hydroxylase deficiency are born with female internal and external anatomy, but, at puberty, neither the adrenals nor the ovaries can produce sex-hormones, inhibiting breast development and the growth of pubic hair.
example 2: androgen insensitivity syndrome
People with AIS have a Y chromosome, (typically XY), but are unable to metabolize androgens in varying degrees.
Cases with typically female appearance and genitalia are said to have complete androgen insensitivity syndrome (CAIS). People with CAIS have a vagina and no uterus,cervix, or ovaries, and are infertile. The vagina may be shorter than usual, and, in some cases, is nearly absent. Instead of female internal reproductive organs, a person with CAIS has undescended or partially descended testes, of which the person may not even be aware.
In mild and partial androgen insensitivity syndrome (MAIS and PAIS), the body is partially receptive to androgens, so there is virilization to varying degrees. PAIS can result in genital ambiguity, due to limited metabolization of the androgens produced by the testes. Ambiguous genitalia may present as a large clitoris, known asclitoromegaly, or a small penis, which is called micropenis or microphallus; hypospadias and cryptorchidism may also be present, with one or both testes undescended, and hypospadias appearing just below the glans on an otherwise typical male penis, or at the base of the shaft, or at the perineum and including a bifid (or cleft) scrotum.
example 3: 5-alpha-reductase deficiency
The condition affects individuals with a Y chromosome, making their bodies unable to convert testosterone to dihydrotestosterone (DHT). DHT is necessary for the development of male genitalia in utero, and plays no role in female development, so its absence tends to result in ambiguous genitalia at birth; the effects can range from infertility with male genitalia to male underdevelopment with hypospadias to female genitalia with mild clitoromegaly. The frequency is unknown, and children are sometimes misdiagnosed as having AIS. Individuals can have testes, as well as vagina and labia, and a small penis capable of ejaculation that looks like a clitoris at birth. Such individuals are usually raised as girls. The lack of DHT also limits the development of facial hair.
example 4: persistent Müllerian duct syndrome
The child has XY chromosomes typical of a male. The child has a male body and an internal uterus and fallopian tubes because his body did not produce Müllerian inhibiting factor during fetal development.
There’s another list of these here.