Code-switching and code-mixing are both natural linguistic phenomena. Some scholars use them interchangeable while others separate them. Either way, they refer to the way we speak in different situations. This includes word choice, rate of speech, pronunciation and colloquialisms.
When separate, code-switching refers to switching between different languages or type so language for different situations. This includes literally changing languages, such as from English to French, and also different ways we use a single language. For example, student's do not talk to their friends the same way the talk to their teachers or the same way they talk to a waitress. We use different words with different groups of people (for example, we tend to not swear around our parents) and different rates of speech in different situations (we strive to be more clear when speaking to a second language learner or someone who is hard of hearing).
When separated, code-mixing means that you take two separate languages or subsets of language and used them together. A pidgin language is an example of this, but more informally it is also code-mixing when you are blending any two subsets.
A prescriptive linguistic model sometimes condones code-switching and mixing as incorrect use because it is not adhering to any one "true" model. However, a descriptive linguistic model, such as transformational grammar, see it as a natural and functional part of language use.