In Old English, thou was singular and you was plural; but during the 13th century, in Middle English, you started to be used as a polite form of the singular – probably because people copied the French way of talking, where vous was used in that way.
English then became like French, which has tu and vous both possible for singulars, giving speakers a choice.
It was usual for you to be used by inferiors to superiors – such as children to parents, or servants to masters; and thou would be used in return. But thou was also used to express special intimacy, as when addressing God, and it was usual when the lower classes talked to each other. Upper classes used you to each other, as a rule, even when they were closely related.
Accordingly, changing from thou to you or you to thou in a conversation always conveys a contrast in meaning - a change of attitude or an altered relationship. The potential role of thou as an insult, for example, is made clear by Sir Toby Belch, who advises Andrew Aguecheek to demean his enemy by calling him thou a few times (TN III.ii.43). Not all instances can be so clearly interpreted, and attitude glosses given below should be viewed as suggestive only.
The old singular/plural contrast may also still be seen, as in Hamlet’s switch from ‘Get thee to a nunnery’, spoken to Ophelia as an individual (Ham III.i.137), to ‘God hath given you one face, and you make yourselves another’, still spoken to Ophelia, but plainly now addressing womankind as a whole (Ham III.i.144).