It depends on your country. My country you get it from The Legal Register Centre which is an agency in the administrative sector of the Ministry of Justice.
The visa lasts for 10 years, with a maximum stay of 5 years. So potentially you could do two stays of 5 years each. Confused? Okay: so you stay 5 years, leave the country, come back again and activate the next 5 years, Simple.
True or not true. So you get always 5-year stamp when crossing the border and extension for another 5 years is not needed provided you make borderhop just before expiredate and apply re-entrypermit if needed outside trips for the last 5 years?