You must have completed at least one academic year with the same SEVIS number (found at the top left side of page 1 of the I-20).
You must apply prior to the end of the 60 day grace period following the quarter/term in which all requirements for graduation are met (for graduate students this means all degree requirements except dissertation/thesis/project).