First of all, CustomROMs for Android are basically alternative operative systems. Of course one could use the term 'aftermarket firmware' but at the bottom the installation of CyanogenMod is the same action as installing linux on a computer with windows preinstalled.
Rooting the smartphone
In order to install a CustomROM on your phone/tablet, you'll need to 'root' it first. Rooting means you will be granted admin permissions for your device. The process differs from device to device but most devices support this procedure without major problems. In most cases you will lose your warranty though. After rooting the device you can access your device with nearly no limits including using apps which need elevated privileges.
Install a CustomROM with a custom recovery
The installation always follows the same basic principles. After rooting the device you got to choose a custom recovery by the community. When you start a smartphone / tablet the custom recovery provides the bootloader which loads the operating system. (If you know linux a bit, yes this is very much like grub2). But a custom recovery can often do a lot more than that:
- Create Backups and restore them
- Partition SD-cards
- Search errors
- Analyze log files
- Install CustomROMs
After the successful install of the custom recovery you simply download the corresponding CustomROM as a zip file and copy it to the SD-card. Of course this can be successfully done by using the (preinstalled) vanilla android. Afterwards you boot into the recovery mode / you start into the previously installed custom recovery. How you get there differs from device to device. In many cases you need to hold one of the volume buttons during startup. Once you have reached the custom recovery mode you can install the zip file with your CustomROM. After the successful installation you restart the device. The first boot of your new CustomROM may take several minutes. Often you are provided with a boot animation which indicates that nothing serious went wrong.