Are you sure your cat likes your petting? If she suddenly bites your hand, you may be violating her personal boundaries.
For example, petting your belly may seem like a cute gesture to you, but to your cat it's an invasion of your inner sanctum.
In the wild, the belly is the most vulnerable area, and touching it causes panic.

Even if the cat turns over, exposing its fluffy belly, this is not an invitation, but a sign of trust. You can touch it only if the pet itself puts your hand on its belly.
The second forbidden zone is the tail. It contains many nerve endings, and even light touches can be painful.
Imagine someone tickling your heel - this is how a cat feels when its tail is stroked.
The third zone is the paws. The pads of the paws are super sensitive: cats use them for hunting and assessing the surface. If your pet does not allow you to touch the paws, do not insist - it is like climbing into a person's mouth.
How to pet correctly? Start with the area behind the ears and under the chin - these are the glands that cats use for marking. Your touch will help them "reinforce" your scent as safe.
Move smoothly from head to tail, simulating licking. If the cat purrs, but twitches its tail, this is a signal to stop.
Never stroke against the grain - it's unpleasant, like having your hair brushed with a sharp brush.
A special case is older cats. Their joints often hurt, and even light stroking of the back can cause discomfort.
If your pet becomes aggressive when touched, take him to the vet. He may have arthritis or an injury you are unaware of.