In the more mundane realm of trials, "impeachment" refers to the discrediting of a witness. In the United States federal court system, impeachment is governed by the Federal Rules of Evidence. In state courts, state evidence rules apply; these are usually similar, but rarely identical, to the federal rules. This writeup assumes the federal rules apply, but if you don't know this stuff already, don't try to use it in a real trial.

Although the party calling the witness can impeach as part of the direct examination, impeachment is much more common as part of the cross examination: most people aren't too keen on discrediting their own witnesses. A good prosecutor, trial lawyer or defense lawyer knows how to mercilessly impeach their opponent's witnesses, and how to keep their own witnesses from being mercilessly impeached by the other side.

In the old days, there was a "confrontation" requirement: to impeach a witness, you had to bring the issue up while they're on the stand. Nowadays, most jurisdictions allow lawyers to impeach witnesses later on in the trial, but many judges still prefer to impose a confrontation requirement in their courtroom, so impeachment will usually happen as part of the cross.

Since leading questions are allowed (and almost always used) on cross, impeachment can theoretically lead to nasty altercations in the courtroom:

Lawyer: Right after the accident, you were found with a crack pipe in your hand!
(jury recoils in shock)
Witness: Ummmm, no.
Lawyer: And then you took out a nine-iron and clubbed twenty baby seals!
(a little girl in the gallery starts crying)

Fortunately, professional responsibility rules generally prohibit lawyers from alluding to anything they don't reasonably believe to be relevant or supported by evidence, so such exchanges are unlikely to happen in a courtroom, unless the witness is really the root of all evil or the lawyer is looking to get disbarred.

Instead, impeachment is usually based on evidence extrinsic to the direct examination of the witness. This evidence may not be seen by the jury, but both plaintiff/prosecution and defense will likely know about it. Such evidence includes:

  1. Prior inconsistent statements. This is the most common method of impeachment. A popular tactic is for the lawyer to pick out differences between the witness's testimony and deposition, and then read the inconsistent statements out loud, one by one, asking the witness to follow along on a separate copy and "correct me if I'm reading this incorrectly." Written reports, like police reports or medical reports, can also be used in the same way; a lawyer can even try to impeach a witness by using their prior spoken statements, although they'll need proof of the statements if they don't want to look like a putz when the witness says "I don't remember."
     
  2. Bias or motive. Many witnesses have an ulterior motive to stretch the truth or tell outright lies; maybe they've had a long rivalry with the opposing party, or a strong prejudice against their race or religion. Lawyers have fairly broad leeway to ask about such matters, and if the witness denies them, other evidence can be brought in later to prove the bias or motive exists.
     
  3. Contradictory facts. If key parts of the witness's story are contradicted by extrinsic evidence, the lawyer can bring in that evidence to impeach the witness's testimony. These contradictions can be introduced later in the trial through other witnesses, although as stated above, many judges prefer to have the contradictions raised on cross-examination before they are proven. When an expert witness says something contradictory to accepted scientific fact, the lawyer can pull out a generally-respected treatise in the field and point out its disagreement with the expert's claim, in much the same manner as introducting a prior inconsistent statement.
     
  4. Prior convictions. These are subject to several rules designed to keep ex-convicts from being discredited solely because they have a criminal record. Under the Federal Rules, a prior conviction cannot be used to impeach unless it carried a maximum sentence of more than one year in prison, or involved untruthfulness or dishonesty (petty theft comes in; running a red light won't). There are also rules that severely limit the admissibility of convictions as a juvenile, and convictions more than ten years old. Details of the crime usually can't come in, besides the type of crime and the accompanying sentence.
     
  5. Character. A party can bring in a character witness to impeach another witness by testifying to their "reputation for untruthfulness," or to their broad opinion that the witness is not trustworthy. If this happens, the other party is allowed to provide their own character witnesses to testify to opinions of truthfulness or truthful reputation.
     
  6. Untruthful conduct. A party can ask a witness about any past conduct that would indicate their untruthfulness. However, they cannot bring in extrinsic evidence to prove that conduct, unless the conduct falls into another kind of impeachment or is relevant to the case itself.