Why Were Medieval Castles Built?

Medieval castles were built for several reasons. First, the castle was a home to the family living there, and to their servants. Secondly, but also important a castle was constructed to provide protection for everyone living in it.