The short answer? Twelve years of good conduct.
In the Navy, there are many different ways to reward a sailor for their excellent work performance, like a promotion in rank or special liberty (time off). On the contrary, there are also several ways to discipline a sailor, for instance using non-judicial punished or Captain's Mast.
A service member falling asleep on watch, destruction of government property or theft are just some the reasons why a sailor would get sent to stand in front of their commanding officer for disciplinary action.
If a sailor is found guilty of a violation, the 12-years of good service starts over. Punishments for violations can range from restriction to discharge, depending on the severity of the offense.
To rate the gold stripes, the sailor must complete 12-years straight of good service with no breaks starting on the first day they wake up in boot camp — not the day they entered basic training.
If the sailor does take a break from service, the period pauses until they return.
So if you notice a sailor wearing three or four service stripes on their sleeve (each stripe means four years of service) and they aren't yellow, chances are they've been in trouble at least once