Question: Most of the time in all the Spanish speaking countries I've been in I've heard ***de nada*** as the reply to *gracias* or the equivalent of English *you're welcome* etc.

But after a while I became conscious that sometimes some people were instead saying ***por nada***.

Are they actually used in different grammatical situations? Does the *de* vs *por* depend on something in the topic of what the thanking was about?

Or is it purely up to how the speaker feels, or is one more prevalent in certain places? Or is one less formal or not condoned as official by the RAE?

Answer: 
I spent time in Chile and my understanding is that the two options mean the same thing in general, but "de nada" is more formal. Saying "por nada" implies that whatever the person is being thanked for doing or saying was so simple and easy it doesn't deserve a thank you.

For those thinking it means "Thanks for nothing", remember that, in this context, "por nada" would be a response in conversation and not said by just one person.
Eva: "¿Puedo usar tu lápiz?"
Tomás: "Claro, aquí está."
Eva: "Gracias."
Tomás: "Por nada."
Por nada is more like saying "no problem" than "your welcome", so its a less formal response.