A cookie stays on your hard drive until you delete it or your browser does, depending on its expiration date.
The code of persistent cookies contains an expiration date, but their duration can vary.
The ePrivacy Directive specifies that they should not last longer than 12 months, but in practice, they may remain on your device much longer if you do not remove them.
You can see what kind of cookies a website places by going to the developer tools in your browser. Check it out!