I'm not from Spain but I think the following will work anywhere, basically. What you're referring to is called the T–V distinction and, though it shows itself as a distinction between formal and informal registers, that's not always the case. Moreover, formal and informal contexts are defined in different ways in different cultures and regions.
In most Spanish-speaking places nowadays the V in the T–V distinction (the "formal" register) tends to be used
- when addressing someone older than you (older by one or more generations, really) or simply above a certain perceived age;
- when addressing a client in a business, taking into account the formality of the business itself (a bank should be considered more formal than a street vendor's stand, in general);
- when addressing someone who commands respect in a formal setting, such as a conference or lecture.
The "informal" register (T form) will be used elsewhere.
If you're a young person (or look like one), then people on the street will probably address you using the T form (tú), unless they are younger themselves. This last point depends a lot on the culture; in some places children might be taught to address anyone they don't know as usted, and carry that into their teenage years and beyond, while some might grow up speaking informally all the time except to certain authority figures.
If you're an older person, then people will tend to address you using the V form (usted), and you might get that even from people of your own age.
Obvious non-native speakers will be forgiven if they use the "wrong" form. If you're out in the street asking for directions you won't do wrong if you use tú for people your age and younger, and usted elsewhere (or if in doubt). Beginning with a light apology (Disculpa...) will help as well.