In the first phase, you go over your security forms (SF-86 and related) in detail with your polygraph examiner. They ask a lot of detailed questions, sometimes including things you aren't legally required to disclose (drug use and foreign travel outside the listed time limits).
In the second phase, they hook you up to the polygraph and ask two series of very specific questions, one called "lifestyle" and one called "national security." Lifestyle questions include questions about drug use, possible crimes, etc., and national security questions include questions about foreign contacts, involvement in terrorism, etc. They're very specific, like "Are you withholding any information about your involvement with illegal drugs in the past ten years?"
About half the time (based on my discussions with other prospective interns), the examiner becomes convinced you're lying about one of these questions and really drills into you. Most of the polygraph examiners are past FBI or CIA interrogators, so they know how to make you very uncomfortable.
I was explicitly told that I failed my first polygraph (the examiner was convinced I used more drugs than I let on), but some of the other interns were drilled about crazier things, like contacts with foreign governments or involvement with terrorist groups.
If you're particularly desirable to the managers who're looking to hire you, they'll keep inviting you to take more polygraphs, and you'll eventually pass.
I ended up turning down the NSA internship for better opportunities after realizing that NSA folks are not the most fun people in the world to hang out with.