1. people who apply for jobs they see ads for, by just doing the phone screen + showing up at the interview; and
2. people who know someone who works at the company, have heard stories of how the company is, see people from the company getting lunch around town, might have even informally asked the person-qualified-to-make-hiring-decisions whether they're hiring--and then go through the interviewing process.
In the latter case, you obviously know exactly what the dress code is like before getting there.
Just ask your contact something like "Should I wear a suit and tie, or is business casual ok?"
If you can afford to say you wouldn't want to work at a place that expects a suit and tie for an interview, that's great -- but not everyone has that luxury.
Asking what to wear has generally worked just fine for me.