When you score a critical hit, roll for damage normally. Then determine the maximum amount of damage you can roll with your attack before applying any modifiers. Combine with maximum result with your rolled damage, and then add your modifiers. This is your critical hit damage.
For example, a Fighter with a 16 Strength score attacking with a long sword strikes a creature and rolls a critical hit. The damage they would inflict would be equal to 8 (the maximum damage for a long sword wielded in one hand) + 1d8 + 3 (Strength modifier) + Any other modifiers, such as a +1 from the weapon being magical.
In the case of bonus dice of damage gained on a attack, such as from spells, magic items, or class features such as the Paladin's Divine Smite or the Rogue's Sneak attack, the dice are still doubled and all rolled as normal. However, if the DM and the table are comfortable with Paladins and Rogues becoming unstoppable killing machines, the rule of maximizing the original pool of dice and then rolling the bonus dice from the critical hit could still be applied. Just bear in mind that this could mean a 5th level rogue's Critical Sneak Attack would be gaining 18+3d6 damage!