This is a phenomenon called vowel reduction.
A good starting point would be the Wikipedia article on Russian phonology: https://en.wikipedia.org/wiki/Russian_phonology#Vowel_mergers
In a nutshell, most Russian dialects distinguish о and а and pronounce them more or less the way it says on the tin when they're stressed, and merge them (pronounce a neutral schwa instead of clear о or а) when they're unstressed.
There are some Russian dialects which (mostly) don't merge о and а even if they're unstressed, and those dialects are readily understood by practically any Russian speaker, although they do sound peculiar to those not accustomed to them.
You can't go pronouncing а instead if о or the other way around all the time. You have to separate them when they're stressed either way, and if you're unsure, you can always just pronounce them as а and о, respectively, even if they're unstressed. You'll be understood.