There exist different variants of discrete cosine transforms. They mostly vary on a phase shift. The most commonly-used type is known as type-II. Since the works of K. R. Rao et al. in the seventies, it was shown to possess near-optimal properties.
The DCTs are invertible, possess certain symmetry properties that make them useful and practical in sound (signal) or image processing. They can technically be applied to any patch size 13, 8x8, 25x32... Power-of-two patches benefit from faster and more optimized computations. 8x8 are standard for natural image due to:
- a size small enough so that image chunks are stationnary enoguh to be quite-well represented by cosine waves
- a small memory footprint for digital implementation
Now, it is more common to find 4, 8, 16, and 32 sizes in image and video coding, and even non-square blocks (4x8) with close to DCT transforms.
The quality is not a real question for the DCT, since it is invertible. It is more related to a match between your data, the transform on the processing (e.g. compression). You might have data and applications where a 25x25 DCT would work better. Then you will probably hit some difficulties for optimized implementations.