Child custody and guardianship are legal terms which are sometimes used to describe the legal relationship between a parent and his or her child. It includes such things as the right of the parent to make decisions for the child, and the parent's duty to care for the child.
In general: decisions about who will have custody of a child will be taken in such a way as is best for the child.
A child may be given state custody. This may be because the child is in danger when living at home. There may, for example, be violence in the home.
When there is a divorce case, a decision will be made about whether the mother or the father has custody of the child. There may be "joint custody", which means that both parents have custody over the child.
Physical custody means: who looks after the child from day to day. It is about where a child will live.
Legal custody means: having the power to make decisions about the child, e.g. where he or she goes to school etc.
If a child lives with one parent, that parent has "sole physical custody". He or she is the "custodial parent". The other parent is the "non-custodial parent", but they may have the right to visit the child.
The laws about child custody will vary from one country to another.