Network Rail's Â£50m Great Western Electrification Programme aims to cut journey times on the route between London Paddington to Swansea.
Rail passengers have been warned of a summer of disruption on the line.
To accommodate overhead power lines, 10km of track to the east of the city, and in the Box tunnel, will need to be lowered and some bridges altered.
It will involve the lowering of track through Dundas Aqueduct, Box tunnel, Middle Hill tunnel and Sydney Gardens, to avoid making changes to historic infrastructure there, Network Rail says.
Eleven new sets of points will also be installed. Replacement bus services will be in use during the work.
"The preparation work we are doing in Bath is essential to make the line ready for electrification," says Andy Haynes, Network Rail's project director for the west of England who also apologised to rail users.
"I know that many people want to travel to and from Bath over the summer and I would like to stress that Bath remains open for business during this time, albeit your journey may take longer than usual."
Between 18 and 31 July the line between Chippenham and Bath will be closed but services via Melksham will run.
And during August all lines to the east of Bath will be closed for a month.
This means there will be no trains running between Westbury, Freshford and Avoncliff to Bath Spa and journeys towards London from Bath Spa will be routed via Bristol Temple Meads and Parkway.
Work has started to prepare the main rail line through Bath for electrification works.