From the IRS
I think this is the most relevant part:
In general, to be a taxpayer’s qualifying child, a person must satisfy four tests:
- Relationship — the taxpayer’s child or stepchild (whether by blood or adoption), foster child, sibling or stepsibling, or a descendant of one of these.
- Residence — has the same principal residence as the taxpayer for more than half the tax year. Exceptions apply, in certain cases, for children of divorced or separated parents, kidnapped children, temporary absences, and for children who were born or died during the year.
- Age — must be under the age of 19 at the end of the tax year, or under the age of 24 if a full-time student for at least five months of the year, or be permanently and totally disabled at any time during the year.
- Support — did not provide more than one-half of his/her own support for the year.
If a child is claimed as a qualifying child by two or more taxpayers in a given year, the child will be the qualifying child of:
- the parent;
- if more than one taxpayer is the child’s parent, the one with whom the child lived for the longest time during the year, or, if the time was equal, the parent with the highest AGI;
- if no taxpayer is the child’s parent, the taxpayer with the highest adjusted gross income (AGI).