Although much of CKII consists of inheritance through family, usually a father to a son, there are some succession laws where the nobles of a kingdom cast their vote for their new King, Queen, Emperor, Kaiser, Basilius, Khan, etc. Although there are several types of democratic governments, these are the most common and most likely. Dukes and Kings are usually the electors of a kingdom/emperor, but counts can vote for their duke if a duchy has elective monarchy or elective gavelkind. There is no limit to the number of possible candidates, and the highest title holder (the title the heir is set to inherit) will break ties.
Help! My vassals are voting for someone I do not want!
A common problem with elective monarchy is the actual electors of the game. A member of your dynasty could be an ideal ruler, but may or may not be voted in. Vassals will always vote for someone with their culture, so granting a duchy to a foreigner is usually a problem, they will vote for themselves or someone else of their culture. Vassals also will want to put themselves or their family onto the throne, so be wary of too many vassals of the same dynasty all voting. The more electors there are, the harder it is to control them. Vassals will also vote for friends or their friend's heir, and this will usually trump over themselves or their children, gaining a vote in favor of the friend.
What vassals vote for
Vassals tend to vote based on a few traits, some minor and some major. Major factors include diplomacy skill, family, and relationship with the nominated candidate. Minor factors include: age, prestige, overall skills, and claims to the throne. Diplomacy is the most important factor for vassals. It is difficult to get electors to vote anyone with under 10 diplomacy to be the new ruler. A ruler skilled in all stats except diplomacy will likely have a tough time being elected, even if they are a far better ruler than the nominated opponent. For example a brilliant strategist with the strong and quick trait and overall excellent skills, but with 8 in diplomacy would likely lose to someone with the imbecile trait, but who has more than 10 in diplomacy. Family is another major factor. Family will try to keep or get their dynasty on the throne, so they will band together and work together. Family is not just limited to dynasty last name though, so cousins, uncles, or fathers who married matrimonial or landed females who married regularly will favor their children more than or equal to their dynasty. Finally, relationship with the title holder and their heir is important. Rivals will never vote for each other, while friends almost always do. Loyal vassals with good relations will usually vote in favor of their ruler's candidate, but are susceptible to voting friends and family, like all electors. Disloyal or indifferent vassals oftentimes vote for another heir, while vassals who despise all candidates or have no political reason will vote themselves. If a vassal does not have an obvious heir or friend, they will likely vote themselves. Age is a minor factor in the election process, but electors seem to slightly prefer older candidates in their 40s or older. This is not extremely significant, but it does seem to change a couple votes. Prestige of a dynasty and a member of that dynasty also is a minor trait, vassals like higher prestige candidates but can be persuaded to vote for someone with lower prestige. This ties somewhat with age, older vassals or candidates have more time to gain prestige. Another factor is claims to the throne. If a vassal has a claim, they will be very likely to nominate themselves, and will attract some supporters.
This is only applicable for players with the merchant republic dlc. Patrician Elective revolves around 5 noble families of
a republic. In a republic, the reigning ruler's dynasty will always have a spot on the 5 noble houses, and is most likely to win an election due to usually having the best resources. The other 4 noble dynasties are vassals/mayors who will seek to put there hiers on the ruler's throne. Should all male members of a noble house die, the game will generate a random new dynasty to replace extinct dynasty. Patrician Elective involves a ruler/noble house leader selecting a designated heir, any male member of their dynasty, to be a candidate in an "election". The "election involves commoners voting and is unable to be influenced directly by the player. The player can and usually will donate money to their heir's campaing fund to win the election. The heir to the republic is calculated by whoever has the most respect, which is gained mainly through age and campaign funds. The candidate with the most respect will win the election and become the new merchant ruler. Common voters love older characters, so it is usually best to not even attempt to select a candidate under the age of 35 unless the player is willing to submit significant amount of money to their campaign fund (be prepared to raise over 1000 gold). Children under 16 will have 0 respect, while elderly prestigious characters can have over 10,000. The best way to win is to assianate elderly members of the other 4 competition dynasty and selecting the oldest member of your dynasty, even if they are not the best option. Republican rulers tend to have short reign times, as most are well into their 50s or 60s.