In England Bayley studied law, and he was called to the bar in 1857; he returned to India on the outbreak of the mutiny later that year. In September 1857 he was ordered to Allahabad, where he served as an under-secretary in Sir John Peter Grant's provisional government, and held various posts in that city during the next eighteen months. In 1859 he was appointed judge in the Fatehgarh Sahib district, and, after serving in a judicial capacity at Lucknow and Agra, was called to Calcutta by Lord Canning in May 1861, to fill the post of foreign secretary pending the arrival of Sir Henry Marion Durand.