You crouch-jump, and shoot a rocket at your feet.
Make sure you're as far as possible from the ground the moment the rocket hits the ground to make sure you're not damaged too much. The last part might take some practising.
By the way, Valve has included a training weapon in the game called the Rocket Jumper. With it, you get twice the ammo and no self-inflicted damage. It's not useful out in the field, really. It can be crafted or bought in the Mann-Co store for $0.49 / £0.29 / €0.49.
(Powerlord mentioned this in the comments to the question above)
The default sniper rifle deals 50 damage un-charged, and 150 damage when fully charged. It takes 1.5 seconds to reload the sniper rifle after the first shot, and a further 3.3 seconds to fully charge it. A level 3 sentry has 216 hit points.
The quickest way to destroy a level 3 sentry is one fully charged shot, followed by a one-sixth charged shot. It takes 3.3 seconds to fully charge one shot (150 damage), 1.5 seconds to reload, and 0.528 seconds to charge it 16% of the way (66 damage), for a total of 5.328 seconds. Slightly slower is five uncharged shots, requiring four reloads taking a total of 6 seconds.
The quickest way to destroy a level 1 or 2 sentry is a series of quick shots. A level 2 sentry has 180 hit points, and will be destroyed by one charged shot and one quick shot (total 4.8 seconds) or four quick shots (total 4.5 seconds). A level 1 sentry has only 150 hit points and will be destroyed in one charged shot (3.3 seconds) or three normal shots (3 seconds).
If an engineer starts repairing the sentry, he can heal 105 damage per hit, every 0.8 seconds. If the engineer is continually healing his sentry, you can't fire the second shot quickly enough to destroy it. If he has no dispenser, he will run out of metal before you run out of ammo, but it will take around thirty seconds.
Alternate weapons: Two weapons are even faster than the default sniper rifle for taking out sentries. The Machina deals 173 damage instead of 150 when fully charged, and can take out a level 3 sentry in one charged hit plus one uncharged (4.8 seconds). The Sydney Sleeper charges 25% faster and can take out a level 3 sentry in 4.748 seconds.
Best Answer
Outside of an uber-charge, if you manage to reach a sentry gun before it can turn to face you, you can circle-strafe it... that is to closely run around it in a circle while facing and attacking it.
This works best as Pyro and Scout, although a Your Eternal Reward Spy with no disguise can uncloak and circle-strafe a sentry to plant a Sapper on it as well.
Note: You have to watch which way the sentry is turning and circle it in the same direction.
Note 2: It's also important to note that circle-strafing fails if the sentry is flush against a wall. However, since it's much harder for an engineer to hide behind a sentry that's against a wall, most Engineers won't build them that way.