It seems that they say "desu/masu" is polite form and "da" is casual form.
I believe, however, as a native speaker, desu/masu is usual (or normal, or normally casual) form, and "da" or so-called 'タメ口' is an unusual form which is used only among close friends where anything goes.
So I believe you don't have to switch it. You can have intimacy even using 'desu/masu' form because it is usual.
If you get into close relationship/friendship with others, sure you will know when to switch your speaking form on your own without knowing rules, because it is close.