Generally this is defined by the paperwork you sign when you are hired. There is some variation across companies, types of positions and countries. It's not unusual to sign an agreement where all the work you do for the company is owned by the company - in other words, you can't take source code, design work, tests, etc. and sell them to a second company. Same thing for the binary. It's called "work for hire".
For salaried employees, I'd say that was the norm. There are circumstances where a programmer may get hired to develop a tool or a solution for a company where this is not the case - for example, I believe a few of the folks I know working on contract for building websites are not obligated to give away the source code - the company wants to own the finished website, but if the employee reuses components of the website in subsequent work for other companies, that's fine.
Also, in most companies both salaried and contract employees sign a Non-Disclosure Agreement (NDA) which covers ideas, proposals and other ephemeral work that relates to the business and it's strategy.
Ownership of code outside the work place is more variable. I can say I have worked in companies where they claimed to own any code I created, even if I did it on my own time for an outside project. But my impression is that this more the norm in huge American companies, and not so typical for smaller, more startup-like companies.