Assuming you're referring to a bicycle drivetrain, the general rule of thumb is to clean and lube your chain every 100 miles. Of course, this varies based on riding conditions - if you live in a dry, dusty area or do a lot of off-road riding, you'll need to clean and lube more often. Likewise, if it rains a lot where you live or ride, you won't need to clean as often since the rain will help wash away any grime and debris.
There are a few different ways to clean your chain - using a commercial degreaser (available at most bike shops), boiling it in water (if it's really caked on with gunk), or just using hot soapy water if it's not too dirty. Whichever method you choose, be sure to rinse the chain thoroughly afterwards and dry it before applying fresh lubricant. Applying lube while the chain is still wet will cause the lube to attract dirt and grime, defeating the purpose of cleaning in the first place!