The rule is that pdu_length+pad+trailer = a multiple of 48 (the number of payload bytes in an ATM cell. Since, for any given PDU, the length is fixed, and the trailer size is fixed (8 bytyes from memory) it is an easy exercise to determine what the pad length should be (it will always be between 0 and 47). DO NOT recalculate the "length" field in the trailer, as it indicates the length of the real PDU. I believe that the CRC does include the padding though...
J