To insert page numbers in your PDF's header or footer, use the {{!PageNumber}} and {{!PageCount}} merge fields. To do this, go to  Template Editor > Insert Field > Special Merge Fields.

Note: This feature previously used HTML/CSS and has since been updated to no longer require code in order to add page numbers to your PDF.