Keeping your bicycle chain clean can really increase the lifespan of your drivetrain, not to mention making it quieter and more pleasant to ride.
If you have a bicycle with a rear derailleur, the easiest and best way to clean the chain is with an on-bike chain cleaner. For me this gets chains cleaner than the method I describe below (removing the chain and washing it) because the chain cleaners have brushes that get between links, and honestly I'm just not willing to go to that much effort manually. FWIW I find the Finish Line chain cleaner ($20 on Amazon) to be good and durable. I just use warm water with a small squeeze of Dawn dishwashing soap in it, then dry and lube.
If you have a single speed or internally geared hub bike, you'll need to remove the chain from the bike to clean it properly. Before you do this, make sure you have a master link to put the chain back on again. If your chain doesn't have one, you'll have to get one. There are at least two different sizes of master link, but for single speed the 7/8 speed links are pretty much universal. Don't get 9/10 speed master links
Step one, remove the rear wheel, using whatever method is normal for your bike.
Step two, if you have a master link already, find it, separate it and remove the chain from the bike. If you don't, then use a chain tool to remove a pin. Also remove the adjacent pin on the half link with the outer plates, so that the chain's two ends are the half links with the narrower, inner plates, which will be compatible with your master link later.
If your chain is quite dirty, as was mine when I cleaned it in January after a few hundred miles of winter snow/salt/slush riding, it'll look like this:
I really do not advocate letting a chain get that bad, but in the winter time, when it's well below freezing, I just can't bring myself to work on the bike much, and besides, a clean chain will look like that after 2 days of riding, so it's hard to get up much ambition for the job. Still, it should be done at least occasionally. In the summer, I would never let a chain get to this point.
Get a plastic jar that can easily fit the chain inside. I use a peanut butter jar. You probably want to use plastic, not glass. Put the chain in there and we will begin a series of washes. Generally I do one in hot water to start with, just to bust loose the random salt and mud. Then I follow up with at least 3 or 4 washes with hot water and Dawn dishwashing liquid. Finally I'll use hot water and a tablespoon or so of Simple Green.
For each wash, swirl the chain around, then let it sit for 10 minutes or so, then swirl again vigorously for 2 minutes or so. Drain, rinse, and go to the next step. After the last step, do one more with just hot water again. Take the chain out and let it dry.
Lubricate each link with your choice of fluid. Apply the lubricant to the edge of the chain, drawing it across both sets of plates and the roller. If it's cold out, let the chain sit for half an hour or so inside to let the lube get inside the rollers. I'm currently using Chain-L, which is extremely thick, like honey, and stays on the chain really well. But others have their own preference, so whatever you like. Finally, put the chain back on the bike.