This is the one thing most clients get wrong. When I first becamse a prosecutor, I was amazed at how many cases are built around a confession. Clients think they can talk their way out of trouble or that remaining silent will look worse than talking. Cop have tactics to encourage people to talk, such as "minimization" and accusatory questions. Most people are shocked to learn that cops are allowed to lie to suspects to convince the suspects to talk.
Regent U. law professor James Duane does an outstanding job explaining why even the most innocent of suspects should never talk to the police absent a lawyer. Unfortunately, most citizens do not learn this lesson until it is too late. For that reason, it is often important to address a client's statement to the police early in the case to determine whether it is admissible in court against him or her. It's a long video, but it's worth it.
If you are detained (meaning you aren't free to walk away) by an officer, you should wait until you've consulted with an attorney before dealing with the police. Give them your correct name and date of birth (or SSN) and then ask if you are free to leave. If you are, leave. If you aren't, ask for a lawyer.