The rules for electing a pope are, shall we say, a bit complex. Here’s just a few links to help you navigate the legal intricacies:
Universi Dominici Gregis, John Paul II, February 22, 1996
(This document lays out the official rules for the conclave completely.)
De aliquibus mutationibus in normis de electione Romani Pontificis, Benedict XVI, June 11, 2007 (Latin only, sorry! This document re-establishes the requirement for a 2/3 majority vote in all cases. In the 1996 document linked above, the requirement was for a simple majority only after a certain number of inconclusive votes.)
Motu Proprio Normas Nonullas, Benedict XVI, February 22, 2013 (I linked the English text at NCReporter, but you can get the Italian and Latin on the Vatican website. The main thrust of this short document is to allow the conclave to convene earlier than Universi Dominici Gregis requires.)
Code of Canon Law on the Cardinals might also be helpful.