If a man's army/regimental/service number is not already known, it is likely to involve some research into surviving WW1 or 2 records and correlation with known family history to achieve an identification.
The majority of WW1 personal service records are now accessible online via subscription sites. Focusing on the British Army, in particular:
The 40% of other ranks' service records which survived the WW2 Arnside bombing are available to view and download from Ancestry UK and Find My Past.
Similarly, the pensions records (service records retained for pensions purposes, which cover fewer men, but are more complete) are available on these sites.
Of the two, FMP has substantially better indexing of these records. Both sites require their second-tier subscription to view these records although some libraries offer the facility to their members to access their Library Editions for free, either on- or off-site.
Army officers' personal files are accessible only via The National Archives, either in person or via a researcher or via a paid-for copying service (quotations will be required for the two latter, or a membership costing £5 and a trip to Kew for the former).
The pensions index cards and ledger records (not the same as the pensions records mentioned above, much briefer but covering many more men) are available to view in full (including images) on the Ancestry subsidiary Fold 3. There is a surcharge for joining this site, alternatively members of the Western Front Association can view for free. A limited transcription (but no image) is accessible via a second-tier Ancestry subscription.
The Commonwealth War Graves Commission website offers a freely-searchable resource for WW1 (and WW2) casualties.
All the foregoing are important records if the regimental/Corps number of the men in question is not known, they do not have a unique name, or their other service details are not with the family. This is because these types of record are likely to have details of next of kin/dependants/home addresses, etc which can help link-in a man (and his regimental number) to known family history and confirm an identification.
On a second tier of usefulness, the Army Medal Office's Medal Index Cards (free to view on Ancestry) sometimes - very rarely for Army other ranks but generally for officers - contain address details, which can be useful as set out above. Images of these cards (both sides) are freely available to view via Ancestry. Partial transcriptions are available via Find My Past and Forces War Records (subscription service) but are (in my opinion) of very little use. The black and white scans of the front sides of the cards (only) which are hosted on the fee-paying The Genealogist website are better than the transcripts but still not helpful for identification purposes as the address details are to be found on the uncopied backs of the cards.
Similarly, the daily and weekly casualty lists (images available via The Genealogist and Find My Past, transcriptions on Forces War Records) can be of some use as depending upon the date of publication they may give a casualty's place of residence, enlistment town, or residence of next of kin. Alternatively, the National Library of Scotland (freely searchable via the internet) contains the weekly casualty lists from 1917-on. Casualty lists were reprinted in a range of newspapers and these can be viewed via the British Newspaper Archive (subscription or pay per view), although the ability to gain information is very dependent upon the indexing, which is again dependent on the quality of the print which was scanned for the Optical Character Recognition.
(The Times Digital Archive also contains the casualty lists but its Optical Character Recognition or search function, or both, are too poor in my opinion to really be useful.)
Certain other records/sources will not be useful for associating a man with his regimental number but could be invaluable for filling in details of his service if his service record documents do not survive. These include the medal rolls and battalion/unit war diaries (both Ancestry), medical hospital admission/discharge registers (transcripts on Forces War Records, images on Find My Past)*, and, of course, newspaper articles (British Newspaper Archives). Finally, if a man remained serving in the Army past a certain point in 1921/22, his service records will have been retained by the MoD, where they can only be accessed by request and upon payment of £30. Men to whom this applies are listed by name and number on Ancestry and Forces War Records.
*these records may also give a man's age
In terms of WW2, for all services, far fewer records are in the public domain and those which are, such as casualty and PoW and RAF enlistment and Royal Artillery tracer card records (all available by transcription on Forces War Records except the latter, which is on Ancestry) are unlikely to help connect a man and his service number. The main exception, as noted above, are the records in the care of the CWGC, although these cover only fatal casualties.
More positively, however, the MoD does offer a service for tracing information about WW2 servicemen. No fee is payable for specified next of kin, otherwise £30. See: https://www.gov.uk/guidance/request-records-of-deceased-service-personnel .
For former Coldstream and Scots Guards, records are accessible from the RHQ:
http://www.theguardsmuseum.com/Family-Research
NB some of the WW1 records are available via The National Archives website. Normally £3.50 a download, it is currently free to signed-in users whilst access to the physical archive is restricted, so might be worth exploring. Also, most of the websites offer some sort of free trial.