Code-switching is a tendency to revert to our indigenous language (L1) when speaking a target or second language (L2). Research has shown that children of bilingual homes with double exposure to languages at a consistent rate show evidence of code-switching as early as two years old. These discoveries have granted the question of whether humans acquire one language system followed by another, or if both systems are acquired at the same time. So far, all conclusions are still merely theoretical.
In bilingual adults, code-switching happens during casual conversations with members of the indigenous language group when both persons are speaking their L2. A great example is the use of "Spanglish" in urban areas where English is the first language spoken in social situations, but the code-switch to Spanish happens mostly when two adults of the same native Spanish background are exchanging words. This is what has given place to terminology such as the very urban "NewYork-Rican" Spanish, where code-switching happens at a constant rate.
This being said, code-switching is not monitored language. This means that, whenever it happens, it often is during casual and relaxed conversation rather than during formal speech. Often, code-switching can very well be the result of an imbalance between the L1 and the L2, when the usage of the L2 is more prominent than that of the L1. This is what may cause a slow extinction of dominance of the L1, causing the L2 to take its place whenever words are forgotten. Conclusively, however, code-switching happens as a result of lax and carefree speech, and it does not occur as an automatic result of being bilingual.