Can we talk discharge please?

So why do we often have brown discharge or spotting a few days before period? Why is there a gap in between them?