  Based on a first-principles approach, we present scaling rules for the band
gaps of graphene nanoribbons (GNRs) as a function of their widths. The GNRs
considered have either armchair or zigzag shaped edges on both sides with
hydrogen passivation. Both varieties of ribbons are shown to have band gaps.
This differs from the results of simple tight-binding calculations or solutions
of the Dirac's equation based on them. Our {\it ab initio} calculations show
that the origin of energy gaps for GNRs with armchair shaped edges arises from
both quantum confinement and the crucial effect of the edges. For GNRs with
zigzag shaped edges, gaps appear because of a staggered sublattice potential on
the hexagonal lattice due to edge magnetization. The rich gap structure for
ribbons with armchair shaped edges is further obtained analytically including
edge effects. These results reproduce our {\it ab initio} calculation results
very well.
