I'm thinking around the 1700s. You hear of illegitimate children of royalty often but how did they determine this? I.e. What if the child was born to a woman who had been with multiple partners? What if a woman was unfaithful to her husband?
In probably the majority of cases in the eighteenth century, it was obvious that the child was illegitimate because the mother was unmarried - it's really the easiest and most visible clue.
For instance, sexual activity before marriage was far from unknown amongst all but the elite, when there was an engagement or an understanding that the couple would get married; in the majority of cases, there wasn't enough time between the activity and the wedding for the woman to conceive, but many others went to the altar pregnant. (I discuss this in this previous answer on premarital sex in Britain as well as this other one on America.) And in some cases, the wedding ... never actually occurred, leaving the woman high and dry with an obviously illegitimate child. Legally, if she named the father while in childbirth, that would be taken as fact, and the parish would go after the man to ensure that he paid some type of support for the woman and her child, but the level of shame in bearing an illegitimate infant was so high that huge numbers of women chose to try to conceal their pregnancies and get rid of the baby after it was born, if they couldn't induce a misscarriage.
These relationships were typically somewhat equal, socially, but a very frequent situation with illegitimate births was for the man to be a social superior to the woman. (If they were equals, they would usually get married, and if she were his social superior she probably would not have risked her reputation by sleeping with him.) Men coerced and raped female servants, visited sex workers, and maintained dependent mistresses. But once again, it was obvious that any resulting children were illegitimate because the women weren't married.
When it comes to the illegitimate children of royalty, the situation is pretty similar. Whether the father were a king or a prince/royal duke, their mistresses were necessarily below them in station - but were typically involved in long-term, relatively monogamous relationships. George I of Great Britain's mistress, Melusine von der Schulenburg, was an unmarried woman from the lower nobility of Hanover; as princes, George IV and William IV were in semi-marriages with (respectively) a widow of the English gentry and an actress. George would also go on to have a number of other mistresses later in life, ranging from aristocrats to actresses, but these later mistresses were typically married already, which I think gets at your question: how would these women know their children were his? Well ... there's no solid evidence that he fathered any illegitimate children. But in general, the only hard-and-fast way anyone could tell in these situations would be if the extraneous husband stayed away from his wife for the duration of the extramarital relationship - if not longer. To go back earlier than your question, in the seventeenth century, Barbara Villiers unofficially separated from her husband not long after her relationship with Charles II began, and since the king acknowledged her first child (conceived and born before the separation) as his, it's likely that they were not sleeping together before they separated. And, quite relevant to your question, Villiers's last child with Charles is generally considered not to be his! The baby was officially acknowledged by him as a royal bastard, but he reportedly did not actually think she was his. But, in the absence of paternity tests, it was all speculation regarding timing.