Abstract: A test of lepton flavor universality in B ± → K ± μ+ μ− decays, where μ is a muon or electron, as well as a measurement of differential and inclusive branching fractions of a nonresonant B ± → K ± µ + µ − decay with the CMS experiment at the LHC are presented. The analysis is made possible by a dedicated data set of proton-proton collisions at √s = 13 TeV recorded in 2018, using a special high-rate data stream designed for collecting about 10 billion unbiased b hadron decays. The ratio of the branching fractions B(B ± → K ± µ + µ − ) to B(B ± → K ± e + e − ) is measured as a double ratio R(K ) of these decays to the respective branching fractions of the B ± → J/ψK ± with J/ψ → µ + µ − and e + e − decays, which allow for significant cancellation of systematic uncertainties. The ratio R(K ) is measured in a range 1.1 < q2 < 6.0 GeV2 , where q is 0.47 the invariant mass of the lepton pair, and is found to be R(K ) = 0.78+−0.23 , in agreement with the standard model expectation within one standard deviation. This measurement is limited by the statistical precision of the electron channel. The inclusive branching fraction in the same q2 range of B(B ± → K ± µ + µ − ) = (12.42 ± 0.68) × 10−8 is consistent with and has a comparable precision to the present world average value.