EIGRP, which is an interior gateway protocol, uses this number so that it makes sure it only talks to other EIGRP speakers that are in the same AS. For instance, if you have two routers, one with "router eigrp 1" and one with "router eigrp 2," then they would not form an adjacency. This could be important in the event that your organization merges with another. Hopefully, you aren't both using the same EIGRP AS, otherwise any overlapping IP space (e.g. 192.168.0.0) you have will cause a real problem. Of course, in your network, all the routers need the same AS number, which can generally be anything from 1 to 65535.
BGP, which is an exterior gateway protocol, uses this number extensively. First, if a neighbor has the same AS, then BGP uses the iBGP protocol. If a neighbor has a different AS, then BGP uses the eBGP protocol. BGP also uses the number in all of the route advertisements because the "AS Set" and "AS Path" attributes are critical to the operation of the protocol.
With BGP, the AS number is commonly "registered," where it is unique in the world, or it can be taken from the private pool, which can be repeated within each organization just like the RFC1918 IP addresses (e.g. 10.0.0.0/8). However, with EIGRP the ASN needs to be the same throughout the domain.
And in OSPF, the router number is only used locally on the router to identify an OSPF process to the CPU. Which is to say, you could have Router A be OSPF 1 and Router B configured as OSPF 2, and it won't make any difference whatsoever. They'll communicate with each other just fine.
The reason for the option is to accommodate the situation where you might want to have four different instances of OSPF running on a router, enabled by the following commands:
router ospf 1
router ospf 2
router ospf 3
router ospf 4
You could then put different network statements under each process. These processes would all dump the routes they learn into the same routing table, but routes learned on OSPF 1 wouldn't be advertised to OSPF 2's neighbors automatically. For this to happen, you'd have to redistribute OSPF 1 into OSPF 2, etc.
So to summarize, choosing an AS number for BGP is very important. For EIGRP, the number isn't usually important, so long as you use the same number across the domain. For OSPF, it's not important at all, unless you need to run multiple instances of OSPF on a single router. However, for consistency's sake, a best practice would be to number all the processes the same across all your routers.
Tom Lancaster, CCIE# 8829 CNX# 1105, is a consultant with 15 years experience in the networking industry, and co-author of several books on networking, most recently, CCSP: Secure PIX and Secure VPN Study Guide published by Sybex.