For stone built castles the foundations would, wherever possible, been built directly onto the bedrock. The builders would dig down to the rock before leveling it to create the strongest possible foundation. The stones for the walls would be laid directly onto the bedrock.