Whether in the past, future, or at present, any ascetics or brahmins who are experiencing various kinds of psychic abilities have attained such abilities through the development and frequent practice of the four bases of psychic ability.

Dutiyasamaṇabrāhmaṇa sutta - Ascetics and Brahmins (Second)

"Bhikkhus, any ascetics or brahmins in the past who have experienced various kinds of psychic abilities being one, they became many; being many, they became one; they appeared and disappeared; they passed through walls, enclosures, and mountains as though through space; they dived in and out of the earth as though it were water; they walked on water without sinking as though on solid ground; they flew through the air cross-legged like a bird with wings; they touched and stroked the sun and moon, so mighty and powerful; and they controlled their bodies as far as the Brahmā world all of them did so through the development and frequent practice of the four bases of psychic ability.

Any ascetics or brahmins in the future who will experience various kinds of psychic abilities being one, they will become many; being many, they will become one; they will appear and disappear; they will pass through walls, enclosures, and mountains as though through space; they will dive in and out of the earth as though it were water; they will walk on water without sinking as though on solid ground; they will fly through the air cross-legged like a bird with wings; they will touch and stroke the sun and moon, so mighty and powerful; and they will control their bodies as far as the Brahmā world all of them will do so through the development and frequent practice of the four bases of psychic ability.

Any ascetics or brahmins in the present who are experiencing various kinds of psychic abilities being one, they become many; being many, they become one; they appear and disappear; they pass through walls, enclosures, and mountains as though through space; they dive in and out of the earth as though it were water; they walk on water without sinking as though on solid ground; they fly through the air cross-legged like a bird with wings; they touch and stroke the sun and moon, so mighty and powerful; and they control their bodies as far as the Brahmā world all of them do so through the development and frequent practice of the four bases of psychic ability.

What four?

Here, bhikkhus, a bhikkhu develops the basis of psychic ability that is endowed with collectedness arising from aspiration and accompanied by intentional effort, develops the basis of psychic ability that is endowed with collectedness arising from energy and accompanied by intentional effort, develops the basis of psychic ability that is endowed with collectedness arising from [purification of] mind and accompanied by intentional effort, and develops the basis of psychic ability that is endowed with collectedness arising from investigation and accompanied by intentional effort.

Bhikkhus, any ascetics or brahmins in the past who have experienced various kinds of psychic abilities being one, they became many; being many, they became one; they appeared and disappeared; they passed through walls, enclosures, and mountains as though through space; they dived in and out of the earth as though it were water; they walked on water without sinking as though on solid ground; they flew through the air cross-legged like a bird with wings; they touched and stroked the sun and moon, so mighty and powerful; and they controlled their bodies as far as the Brahmā world all of them did so through the development and frequent practice of these very four bases of psychic ability.

Any ascetics or brahmins in the future who will experience various kinds of psychic abilities being one, they will become many; being many, they will become one; they will appear and disappear; they will pass through walls, enclosures, and mountains as though through space; they will dive in and out of the earth as though it were water; they will walk on water without sinking as though on solid ground; they will fly through the air cross-legged like a bird with wings; they will touch and stroke the sun and moon, so mighty and powerful; and they will control their bodies as far as the Brahmā world all of them will do so through the development and frequent practice of these very four bases of psychic ability.

Any ascetics or brahmins in the present who are experiencing various kinds of psychic abilities being one, they become many; being many, they become one; they appear and disappear; they pass through walls, enclosures, and mountains as though through space; they dive in and out of the earth as though it were water; they walk on water without sinking as though on solid ground; they fly through the air cross-legged like a bird with wings; they touch and stroke the sun and moon, so mighty and powerful; and they control their bodies as far as the Brahmā world all of them do so through the development and frequent practice of these very four bases of psychic ability."