Miranda applies when an officer has you (1) in custody; and (2) is interrogating you. Let's take a look at these separately.
"Custody" means you are either under arrest or you are detained, meaning a reasonable person would not feel that they are able to leave. This part is somewhat easy, but not without some exceptions. For example, an officer may briefly detain you and put some questions to you if they believe that a crime is happening or is about to happen. Additionally, if an officer asks you if you are willing to answer questions and you either say you are or just answer questions willingly, the court will call this a "consensual encounter" and the officer does not have to inform you of your rights.
"Interrogation" is tricky. The simple definition is when an officer is asking you any questions designed to get an incriminating answer. "How long have you been beating your wife?" is an example of such a question. "How much money of yours is from selling dope" is another. Simple questions like your name, date of birth, address, and even aliases are not interrogation.
If an officer has violated your Fifth Amendment rights (what Miranda actually protects), any statement made may be suppressed and it is possible that any evidence obtained as a result of that statement may be suppressed as well. But suppression is not automatic. An attorney will write a motion based on the facts of your case, support it with relevant case law and argue it to the judge, but even then it is not always granted. We like to think our system is protective of the accused but it is not always easy. Whether the case gets dropped after suppression depends on what other evidence is available and whether or not the DA can prove the charge to a jury, beyond a reasonable doubt (meaning not all doubt but reasonable doubt) without the suppressed evidence.
Miranda is actually a much more complex area of law than you see on television. If you have been arrested and are charged with a criminal offense, you need to speak with a criminal defense attorney. I practice throughout California. Please contact my office for a free initial consultation.