How were castles ddefended?

Many castles had moats, steep embankments or other natural defenses. Castle defense was often a matter of waiting out the attackers - many castles had their own water supply. Artillery, which could destroy walls, made castles obsolete.