Being a witness and giving testimony at a trial, or in a deposition, can be stressful. Generally, a witness only needs to answer the questions asked. However, it is rather common, especially in depositions, for witnesses to be asked questions they can't answer.
Fortunately, there are three magic words that witnesses can use: "I don't recall." However, the catch is that your failure to recall must be truthful. Though, like most legal matters, a person's recollection can be a nuanced thing that hinges upon semantics. If you think you don't know something, saying you don't recall is often preferable, as people frequently find that they know things without even being aware of having the knowledge.
Testimony and Personal Knowledge
Legal cases require witness testimony to prove each individual element of a crime or civil cause of action. In order to prove a case, attorneys use artfully worded questions to elicit answers that satisfy each required element. Frequently, rather specific factual information is needed to prove an element, and if the only witness cannot recall a specific fact that is necessary to satisfy an important element, then a whole case can be dashed.
When a person testifies in court or at a deposition, rules of evidence require that they have personal knowledge of the facts or testimony. Unlike saying "I don't know," which affirmatively states a lack of any knowledge, not recalling something implies that you may or may not have ever known anything, but as you sit there, you are unable to call forth a specific recollection. You may know, you just don't remember at the moment. Not recalling something presently allows a witness the opportunity to recall it later.
Total Failure to Recall
When a person testifies, they are being asked to provide their best recollection of facts to which they have personal knowledge. Attorneys usually explain that witnesses should not "guess" at answers, but should provide their best estimate if they are not sure. If you are asked for information about exact facts, dates, or times, you may want to just say that you don't recall if you are unsure rather than try to provide an estimate.
Unfortunately, a lawyer can ask questions to pin down what you do recall or your best estimate. For instance, if you can't recall when something happened, you might be asked if it happened within the last five years? Or if it was summertime? Or before or after your birthday? Additionally, if you do not recall something, an attorney can show you documents, evidence, or almost anything for that matter, to spur your memory. If you are just trying to avoid answering a question, be mindful that perjury is a crime, and being deliberately obstructive could result in court ordered sanctions.
Lastly, if you are trying to avoid answering a question due to fear of criminal prosecution based on your answer, then don't forget about your Fifth Amendment rights against self-incrimination.