You're walking home at night when a police car pulls up at the end of the street. The officer gets out and walks over, asking you to stop.
You know that you haven't done anything wrong. You were just walking on the sidewalk. Can you now walk away from the officer, or are you obligated to comply?
Legally speaking, you can walk away. Just stay calm. Tell the officer you're not interested in having a conversation or answering questions and that you want to continue on your way. Then keep going.
Remember, this is true if the officer doesn't have reasonable suspicion or probable cause to make an arrest. As such, some advise simply asking the officer where you stand. Instead, of walking off, ask if you're free to go. If you are, the officer has to tell you so, and then you can leave without incident.
Now, the officer may tell you that you can't leave. Ask if you're being arrested or detained. These are different; you can be detained and then released without an arrest ever going on your record. For instance, this sometimes happens when police are looking for a suspect who looks like you, but, after stopping you, they realize you're not the person they're after.
The key is really just to stay calm and collected, knowing that you have rights that even the police can't violate.
If you believe they have, though, perhaps by making an illegal arrest and then trying to pin charges on you when you didn't do anything wrong -- charges for resisting arrest, for instance -- be sure you know all of the legal options you have.
Source: ACLU, "Know Your Rights," accessed Sep. 08, 2017