The most important and trickiest part of cat genetics is getting a handle on the sex-linked red gene, especially if you want to learn to predict the offspring of two cats. Because this gene is located on the X chromosome, it behaves quite differently from the other genes we'll be looking at.
This is also the reason you might have heard that male kittens take after their mother, while mollies take after both parents when it comes to pelt color. While true in a sense, I strongly advise you to forget it, since it seems to confuse as many people as it helps.
In cats and most other mammals, there are two main types of pigment in the skin and hair. Eumelanin is the black pigment, while phaeomelanin is the red pigment. In cats, eumelanin is responsible for black and brown colors, while phaeomelanin is responsible for red, orange, and yellow tones.
Your typical plain black cat actually has both eumelanin and phaeomelanin in its fur, but because eumelanin is so much darker, it becomes the dominant effect, and you can't see the phaeomelanin's color, except sometimes as a reddish cast in the sunlight. The sex-linked red gene simply prevents the cat from producing eumelanin, allowing the phaeomelanin's color to show. Phaeomelanin-based colors like red are commonly referred to as "red-based", and eumelanin-based colors are "black-based". I also often used "red" and "not-red" colors, as I find that to be less ambiguous.
The tricky bit is that, as previously mentioned, this gene is on the X chromosome. In male cats with only one X chromosome, this is simple - either they are red, or they aren't. But female cats have two X chromosomes to work with, and so they can be tortoiseshell, having patches of both red and black. This happens when one X chromosome has the red allele (XO) and the other has the "not-red" allele (Xo). The O is for orange, but red is the more common breeder's term.
sex-linked red: O locus
Black-based - XoY, XoXo
Tortoiseshell - XOXo
Red-based - XOY, XOXO
If we want to predict how the Red gene will pass on, we need to do a bit of trickery with our Punnett squares. X and Y are mostly preserved as whole chromosomes, so the dam's eggs will get either X chromosome at random, and the sire's sperm will get either the X or Y chromosome at random. Let's try predicting the offspring of a tortoiseshell dam and a black sire.
XO egg + Xo sperm = XOXo = tortoiseshell female
XO egg + Y sperm = XOY = red-based male
Xo egg + Xo sperm = XoXo = black-based female
Xo egg + Y sperm = XoY = black-based male
By this model, male cats can't be tortoiseshells. Usually, this is true, but there are rare cases of just that. There are two mechanics by which a tom can be tortoiseshell.
The first is an intersex condition known as Klinefelter Syndrome. In this case, due to an error in gamete production, the cat ends up being XXY. Because of the Y chromosome, the cat appears to be male, but because of the two X chromosomes, he may be tortoiseshell. These cats are infertile, since the chromosome weirdness messes with gamete formation. Other intersex conditions can also lead to tortoiseshell toms, but this seems to be the most common.
The other, much less common option, is that the cat be a chimera. Chimeras, in the genetics sense, are a fusion of two separate embryos. They appear to be one individual, but genetically speaking, they are a mix of two different individuals. These cats can be fertile, but will breed as though they are either red or black.
For more information on tortoiseshell toms, Messybeast has several articles on the topic.
This visualizer allows you to play with different genes and see what they look like. Each article will add on more genes until every color and pattern is covered!
Sex-linked red has been mapped to a region on the X chromosome, but the exact locus has not been identified. I suspect the O allele somehow suppresses black pigment production rather than making it impossible, as many ginger cats have dark "freckles" on their noses.
Tortoiseshell cats are patched because of X-chromosome inactivation. Essentially, we only really need one X chromosome, as evidenced by the fact that about half the population has only one. Having two would cause some proteins to be over-produced, so cells counteract this by condensing one of the X chromosomes. Which X chromosome is condensed is random, so if a cat is XOXo, some cells will end up expressing O and some will express o. I would guess that variation between larger and smaller patches is what time the X-inactivation happens in development.
I haven't seen a good theory on why white spotting causes larger patches - the only one I have seen is based on an outdated theory of white spotting.
I have also been asked why so many tortoiseshells have more black than red. The answer is, they don't! Very mottled patches tend to read as darker/more black, even if the hairs are interspersed, so unless the tortoiseshell has quite a bit more red (by chance), they will often look more black.