wakatta and wakarimashita are used sometimes in anime. I understand one is informal and the other is formal past tense. When do you have to use the informal and when to use the formal tenses of the verbs? Are there a set of rules or is it something vague?
wakaru is the verb "to understand".
wakatta is its past tense informal form.
wakarimashita is its past tense polite or formal form.
So they both mean "Understood".
As a Japanese learner or foreigner in their country, you should be using polite forms until you make some friends and speak with them "informally".
Also the informal tense is used in some grammar situations, as for:
The relative clause (adjacent adjective):
分かった質問【しつもん】. "Understood question"
結婚【けっこん】した男【おとこ】です. "(he) is a married man".
Most European languages have a clear distinction between formal and informal, which usually shows up as two conjugations for "you." The Japanese have multiple distinctions for politeness/formality, the most obvious of which is the です／ます distinction. However, it is not used in exactly the same way as the European versions.
The explanation I was given for this in university is that です／ます conveys social distance. When you use these forms, you are being polite to the listener, and not claiming them as a close acquaintance. It's a "safe" way of speaking, because you aren't implying a right to address this person as an intimate or subordinate. Of course, it also conveys a certain degree of coolness; it implies that you are not friends, just acquaintances.
In the case of 分かった and 分かりました, they are in the same tense (both are "completed" actions), but at different distances. 分かった is the plain form; it implies that you know the listener well enough that you don't need to be careful or especially polite. 分かりました is the distant form, and has the same literal meaning but is socially more careful, or distant..