Do it little by little.
Like a learner driver, go find a car park or a quiet road
, you don't want to be doing this in the traffic.
Ironically, you probably don't want to be doing this on a surface that will give you a soft landing.
I suppose a flat playing field might work, but cycling on grass isn't as smooth as cycling on tarmac and you'll need a predictable, flat surface to work with.
The biggest skill to master is steering through weight, not through moving the handlebars.
You probably do this anyway, but it's something to work on deliberately while you've got two hands on the bars.
Just sway your weight from side to side and try to go in the direction you want - in a moment you'll be steering like this for real, so try and get it going well when you don't need it.
I don't think it's worth going one handed first
- this is an all-or-nothing exercise.
Get going in a straight line with your hands lightly on top of the bars (if you're on dropped handle-bars) and just relax your hands.
Hold them flat on the bars and just lift them.
Don't look at them.
Just lift them a little.
A fraction of an inch will feel like a foot ...
But then just try to do things with the hands off the bars.
Do the leaning and swaying from side to side.
Just a little amount.
Just enough to drift a little off line then get you back going in a straight line.
Then once you're happy, try to sit up.
The more you practice, the less of a problem this becomes.
You will feel very unsteady as your centre of gravity moves around.
The key here is that on most bikes your centre of gravity is quite low, somewhere around your knees, but as you take your hands off the bars and sit up, it rises significantly, so you need to be happy in controlling it and how to react to how the bike is taking it.
Pretty soon you'll be taking corners.
Of course, don't forget that, unless you're on a fixed or have non-standard equipment, the only way to stop suddenly is probably quite painful ...
bicycles.stackexchange.com/users/425/Unsliced
You should find it pretty easy to pedal with no hands for a second.
Once you're able to do this, progressively leave your hands off the bars for longer.
It's easy to work up to riding no handed comfortably.
Two things you should note: Riding no-handed is actually pretty dangerous.
If you accidentally hit a walnut-sized rock it can turn your handlebars enough to toss you.
Riding no-handed is illegal in some areas, and you can get a hefty ticket (e.g. Ontario).
bicycles.stackexchange.com/users/2824/Darth Egregious
One thing to mention is if the bike is messed up at all, it's a lot harder to ride no-handed.
I have a "beater" I bought for $1 at a garage sale to ride/leave at the train station.
It must have a bend in the frame somewhere b/c I can't let go of the bars
w/out it pulling.
My road bike however, I can go easily and corner no handed.
I think it's easiest to do while pedaling, and to learn to "stear with your hips".
Hope that helps.
bicycles.stackexchange.com/users/853/Don
Half off-topic, as this does not really answer your question, but I think this warning is quite in order, and thus on-topic: Don't ride no-handed .
At the very least, not without shoes that lock into your pedals.
The reason is the failure mode, which I, for one, unfortunately learned the hard way: When you ride no-handed, you have exactly three points of contact with your bike.
The saddle, and the two pedals.
That suffices to keep your balance and allows for steering.
But there is no redundancy at all .
If you loose one pedal from under your foot, you immediately loose the other one too.
Your pedals are connected to each other, and the pressure of one foot provides the counter-pressure from the other pedal to the other foot that's necessary to keep both feet connected to your bike.
After you've lost your pedals, you only have one connection left to your bike, the saddle.
And that is neither enough for keeping balance in the long run, nor for any kind of steering.
You immediately, and utterly loose control over your bike .
It's just game-over.
If your bike is heading for a moat, you'll end up in the moat.
If your bike is heading for an oncoming truck, you'll meet this truck.
You'll neither have a chance of braking, nor to regain control in any way.
When this happened to me, I was heading towards a traffic light that was about 5 to 10 meters away, and there was nothing I could do to reduce the impact.
This encounter got me four weeks on crutches, and a lesson well-learned.
I hope you do learn this lesson from me, instead of learning it the hard way as I did.
bicycles.stackexchange.com/users/36555/cmaster - reinstate monica
I've just re-learned this at age 40.
It's a lot easier (at least for me) on a rigid bike than one with suspension, as the bike is more responsive to shifting your weight.
Also - remind yourself to look ahead instead of down at your handlebars, and make sure you are comfortable perched on the saddle with your weight back - the saddle is going to be the main way you move the bike around.
I agree with cmaster that the best place to do this is away from a road where you would interact with vehicle traffic, as it takes an extra second or two to get your hands on the brakes for an emergency.
There are bike lanes closed to vehicle traffic where I live, and you can easily steer around the odd pedestrian without holding your handlebars.
bicycles.stackexchange.com/users/39519/kamyonet
Learning to ride no-handed has been on my new year resolution list year after year after year and I still haven't done it. I'm 46 so I need to be careful about falling off. Do people have fool-proof techniques for learning to ride no-handed they can share?  Just to clarify after  Daniel 's comment below I have three bikes, a racer, a commuting bike, and a mountain bike. The mountain bike is twitchy but the others feel stable.
How does one ride 'no handed'?
bicycles.stackexchange.com
<technique>
bicycles.stackexchange.com/questions/8924
bicycles.stackexchange.com/users/3704/dumbledad
Riding no-handed is quite dangerous and in some places illegal. To learn this skills, practice is needed. This should be done away from roads. The biggest skill to master is steering through weight, not through moving the handlebars. It may be best to go gradually, riding with the hands lightly on the handlebars and then taking them off when you feel ready.  It should be noted that as you have no hands on the brakes, stopping suddenly can be quite painful. Riding no hands is dangerous and illegal in some places. It is impossible to brake suddenly and a small obstacle can cause you to fall off. If you still want to learn, find a place to practise away from traffic, but with a smooth, flat surface where you have time to stop. Build up gradually by taking the weight off your handlebars, then removing your hands for a couple of seconds. Get used to steering with your hips and body weight and remember that your centre of gravity is higher. Keep pedaling while learning.
Riding no hands is dangerous and illegal in some places. It is impossible to brake suddenly and a small obstacle can cause you to fall off. If you still want to learn, do this away from roads and make sure that your bike is working properly. Find a place to practise away from traffic, but with a smooth, flat surface where you have time to stop. Build up gradually by taking the weight off your handlebars, then removing your hands for a couple of seconds. Get used to steering with your hips and body weight and remember that your centre of gravity is higher. Keep pedaling while learning.