It depends on the country laws, contract and employer.
My contract is based on french telecom legal template which says:
- code specific to the assigned work: all copyrights belong to the employer.
- code *not* specific to any assigned work:copyrigths are shared by the employer and the employee (you need an agreement to work on that code). Namely if the employee departs from the company, he will keep the copyrights.
Of course, there may be more about this in the french law (I was told, french copyrights on code always belong to the employee). And of course, an employer aware of the open source ways would let the copyrights go to the employee or at least be shared.
The main issue with the shared copyrights: the employer would have the right to close the code produced by the employee. And that's a very big issue for GNU GPL coders! You know... those guys who want to have the best open source code installed by default on all systems.
Some people have a great ambition: to build something that will last, at least until they've finished building it.