When should i use it? In what situations? For example, if they explain something to me or ask me not to do something, then these words are interchangeable or not, what shade?
明白了sounds a bit more polite than 知道了. It's subtle but if you are losing your patience and want the listener to stop repeating him/herself immediately, use 知道了. If you want to politely assure the listener that he/she has made him/herself sufficiently clear, use 明白了, or 懂了.
It's similar to the subtle difference between "OK" and "no problem".
If you are asking about the difference between know and understand: We can know about something which we don't understand, such as Quantum Mechanics, but we can't understand something we don't know.
To know about something is the first step to understanding something. If the thing you know about is simple, to know is to understand: If someone is married that means that person has a husband or wife.
I know a secret which has been hidden for many years.
To know about something does not automatically mean you understand it.
*I understand a secret which has been hidden for many years.