This is often due to a urinary tract infection. The bacteria causes inflammation in the bladder, which irritates the epithelial lining of the bladder and often causes bleeding, coming out in the urine.
A urinary tract infection can often easily be treated with a round of antibiotics, but it is not something to put off treating for too long, as it is very uncomfortable for the cat and can eventually lead to either kidney infections or chronic cystitis. Male cats in particular can have a very serious problem with urinary tract infections, because their urethras are so narrow, the crystals that form in the urine can get blocked. If a male cat ever shows symptoms of not being able to urinate, this is fatal if not treated asap.
Your vet will want to check a fresh urine sample to determine which type of bacteria is causing this and if crystals or casts are present, then choose the proper antibiotic for curing. In the meantime, encourage plenty of fresh water intake if you can.
Best of luck, and let me know if I can help further.