How many shingle layers can I put on a roof?

Most building codes allow a structure to have two roof membranes in place, but not a third. The codes are also now requiring all roof layers to be removed once the two roof limit has been reached, when looking to install the third roof.