How long do you serve in the military until retirement?

Is it only 20 years? Do you have to serve in that same exact military branch or can you change. For example, 10 years Navy and another 10 years in the Marines.
9 answers 9