How much time I would get on H1B Visa?

Currently I am on L1B visa and I will complete 5 Years on L1 on May 2016. I am planning to apply for H1B Cap on 2017.

Question:

In case my case get selected in lottery in 2017 and if I travel after on Oct 2017 (After 1.5 years , will I get 6 years or my 5 years on L1 would be counted as my H1B Petition was filed in April 2017 (less than 365 days)

How cooling period works, is it based on the period you stay out of USA or based on the Petition filed?