what do you count as the last day of period?

Everyone says the first day of red flow is the first day of your period, pink spotting doesn't count. So is the last day of red flow the last day of your period? Because I've always had a day or 2 of brown spotting at the end of my period and I've always logged it as my period. So does this mean I've been getting my fertile days wrong if my periods are actually 5 days when I thought it was 7?