Cancer is when a cell begins to rapidly divide without stopping and your body loses the ability to regulate those cells. It becomes dangerous when these cells become able to spread to other tissues.
Every time one of your cells divides, there are errors in the copies of DNA that are made. Many of these will be repaired by specialized enzymes in your body, but some of them won't. Everyone has genes called Tumor suppressor genes (which stop a cell from becoming cancerous) and Oncogenes (normal necessary genes usually involved in cell division that can stimulate cancer if they are messed up) If an oncogene is mutated in the wrong way, and the regulating tumor suppressor gene also gets mutated to inactivate it, cancer can occur. This process really comes down to random chance as cells in your body are dividing every day. This is why chances of getting cancer increase with age as the more times a cell divides, the more likely it is that something will eventually go wrong.
There are also many environmental factors that can increase the risk of errors in DNA replication. Smoking greatly increases chances. Asbestos can do this. Even the rays of the sun can cause mutations in DNA which is why tanning has a link to skin cancer.
There are also some people born with genetic predispositions to cancer due to a genetic deficit in a tumor suppressor gene, but this is actually fairly rare.