The definition of a perfect number is that it is a number which is equal to the sum of all the numbers that divide exactly into it, including 1, but excluding itself. Thus 6 is a perfect number because 6 is divisible by 1, 2 and 3, and the total of those numbers is also 6. As mentioned, the fact that it is divisible by itself, 6, does not add to the total.

Likewise 28 is divisible by 1, 2, 4, 7 and 14, which add up to 28.

That's how the definition works.

It turns out that all the even perfect numbers are given by
(2^(p-1))*(2^p-1) where p is a prime and 2^p-1 is also prime (this form is called a Mersenne prime). It is believed, but not proved, that there are no odd perfect numbers, so that this list, via Mersenne primes, will find any perfect number at all (is in 1-to-1 correspondence with the perfect numbers).

The alternative solution that I posted previously, uses the mere formula (2^(p-1))*(2^p-1) considering only p as prime without requiring 2^p-1 to be prime. This results in numbers, such as 2096128, showing up on the alternative sequence while not being perfect.