There are several factors. One is genetic, you could be born with a mutated gene already (for example the BRCA genes give you predisposition to develop breast cancer); then there are the risk factors that increase the probability that you could develop cancer: the most infamous are smoking, alcool, HPV infection; finally there are the completely random mutations that nobody can predict since our genome keeps evolving through mutations (and this is why it’s more likely to get cancer with aging, because you have had a lot of time to get those mutations)
The cells in your body have to grow and divide to make your body grow, and to replace damaged cells. Each cell contains a copy of your DNA, so each time a cell divides, it has to replicate its DNA, because it goes from one cell to two. Sometimes when the DNA is being copied, a mistake is made: this is what we call a mutation, it’s any change in the DNA. Cells have pretty good proof-reading mechanisms to correct the mistakes, but sometimes a mutation will slip through.
Most mutations are actually harmless and won’t make any difference at all. But some mutations make cells grow and divided faster. So when a cell gets a mutation like that, it grows out of control, and that’s basically what cancer is.
So mutations can happen naturally through little mistakes each time a cell copies its DNA. But some chemicals and environmental factors (like cigarette smoke and UV light from the sun, for example) increase the rate of mutations and so make the chances of you developing cancer much higher.
There are a number of things. Sometimes it is just mistakes that happen when your cells replicate. It can also be caused by ionising raditaion (such as UV from the sun), a bad diet, viruses that change your DNA (such as HIV), or chemicals which damage DNA, such as those found in cigarette smoke.