Shakespeare's sonnets are written according to the English sonnet structure that was developed during the Renaissance by poets like Wyatt, the Earl of Surrey, and Spenser. The originator of the sonnet form was Petrarch, an Italian poet who lived 200 years before the English sonnet poets.
Petrarch used a rhyme scheme that fitted his sonnet structure of fourteen lines comprised of an octave (8 lines) followed by a sestet (6 lines), with no rhyming couplet. The Petrarchan rhyme scheme was abbaabba in the octave, followed by one of several options for the sestet. Some of those options were:
The English sonnet structure of fourteen lines was modified to fit the English language and taste. It is structured as three quatrains (4 lines) and an ending rhyming couplet (2 lines).
The English sonnet rhyme scheme fits this new structure. Shakespeare's Sonnet 18 has an English sonnet rhyme scheme that is different from the Petrarchan rhyme scheme in that each quatrain is two sets of alternating rhyming lines, which produces a rhyme scheme of abab cdcd efef followed by the rhyming couplet, which is gg.